Skip to content

Instantly share code, notes, and snippets.

@smaglio81
Created June 21, 2020 16:43
Show Gist options
  • Save smaglio81/bca389b1f852f82ba823f1166dfd37e5 to your computer and use it in GitHub Desktop.
Save smaglio81/bca389b1f852f82ba823f1166dfd37e5 to your computer and use it in GitHub Desktop.
function Update-AzDServiceHook {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Microsoft.VisualStudio.Services.ServiceHooks.WebApi.Subscription] $Subscription,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch] $Enable,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch] $Disable
)
if($Enable) {
$Subscription.Status = [Microsoft.VisualStudio.Services.ServiceHooks.WebApi.SubscriptionStatus]::Enabled
}
if($Disable) {
$Subscription.Status = [Microsoft.VisualStudio.Services.ServiceHooks.WebApi.SubscriptionStatus]::DisabledByUser
}
$output = ($Subscription | ft -AutoSize Id, EventType, ConsumerId, Status, ActionDescription | Out-String) -split [Environment]::NewLine
Write-Verbose "Updating: $($output[3])"
$shpClient = $global:AzDModule.ServiceHooksPublisherClient
$response = $shpClient.UpdateSubscriptionAsync($Subscription, $null)
if($null -ne $response.Exception) {
if($null -ne $response.Exception.InnerException) {
throw $response.Exception.InnerException.Message
} else {
throw $response.Exception.Message
}
}
return $response.Result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment