Created
June 21, 2020 16:43
-
-
Save smaglio81/765a2042f2642208843ae0db27a90932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-AzDServiceHook { | |
[CmdletBinding(DefaultParameterSetName = "ProjectName")] | |
param( | |
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)] | |
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)] | |
[ValidateSet($null, "git.push","git.pullrequest.created","git.pullrequest.updated","build.complete")] | |
[string] $EventType = $null, | |
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)] | |
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)] | |
[string] $ToUrl = $null, | |
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)] | |
[string] $ProjectId = $null, | |
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)] | |
[string] $ProjectName = $null, | |
[Parameter(Mandatory = $true, ParameterSetName = "SubscriptionObject", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[Microsoft.VisualStudio.Services.ServiceHooks.WebApi.Subscription] $Subscription | |
) | |
$subscriptions = @() | |
if($PSCmdlet.ParameterSetName -eq "SubscriptionObject") { | |
$subscriptions = @($Subscription) | |
} else { | |
$subscriptions = Get-AzDServiceHook @PSBoundParameters | |
if($null -eq $subscriptions) { $subscriptions = @() } | |
} | |
foreach($sub in $subscriptions) { | |
$output = ($sub | ft -AutoSize Id, EventType, ConsumerId, Status, ActionDescription | Out-String) -split [Environment]::NewLine | |
Write-Verbose "Removing: $($output[3])" | |
$shpClient = $global:AzDModule.ServiceHooksPublisherClient | |
$response = $shpClient.DeleteSubscriptionAsync($sub.Id, $null) | |
if($null -ne $response.Exception) { | |
if($null -ne $response.Exception.InnerException) { | |
throw $response.Exception.InnerException.Message | |
} else { | |
throw $response.Exception.Message | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment