Created
October 6, 2021 22:40
-
-
Save vinijmoura/3b934dea8500ebb19a546cb973e559d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Param | |
( | |
[string]$PAT, | |
[string]$Organization, | |
[string]$Connstr | |
) | |
$SQLQuery = "TRUNCATE TABLE ServiceHooks" | |
Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) } | |
$UriServiceHooks = "https://dev.azure.com/$($Organization)/_apis/hooks/subscriptions?api-version=6.1-preview.1" | |
$ServiceHooksResult = Invoke-RestMethod -Uri $UriServiceHooks -Method get -Headers $AzureDevOpsAuthenicationHeader | |
Foreach ($serviceHook in $ServiceHooksResult.value) | |
{ | |
$UriGetProject = "https://dev.azure.com/$($Organization)/_apis/projects/$($serviceHook.publisherInputs.projectId)?api-version=6.1-preview.4" | |
$GetProjectResult = Invoke-RestMethod -Uri $UriGetProject -Method get -Headers $AzureDevOpsAuthenicationHeader | |
$SQLQuery = "INSERT INTO ServiceHooks ( | |
ProjectName, | |
eventDescription, | |
eventType, | |
publisherId, | |
consumerId, | |
consumerActionId, | |
actionDescription, | |
createdBy | |
) | |
VALUES( | |
'$($GetProjectResult.name)', | |
'$($serviceHook.eventDescription)', | |
'$($serviceHook.eventType)', | |
'$($serviceHook.publisherId)', | |
'$($serviceHook.consumerId)', | |
'$($serviceHook.consumerActionId)', | |
'$($serviceHook.actionDescription)', | |
'$($serviceHook.createdBy.displayName)' | |
)" | |
Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment