Created
August 19, 2021 22:07
-
-
Save vinijmoura/3d8abda0965271a962444cfc772a9b9e 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 InstalledExtensions" | |
Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) } | |
$UriInstalledExtensions = "https://extmgmt.dev.azure.com/$($Organization)/_apis/extensionmanagement/installedextensions?api-version=6.0-preview.1" | |
$InstalledExtensionsResult = Invoke-RestMethod -Uri $UriInstalledExtensions -Method get -Headers $AzureDevOpsAuthenicationHeader | |
Foreach ($extension in $InstalledExtensionsResult.value) | |
{ | |
$extName = $($extension.extensionName).Replace("'","") | |
$extPublisherName = $($extension.publisherName).Replace("'","") | |
$SQLQuery = "INSERT INTO InstalledExtensions ( | |
ExtensionId, | |
ExtensionName, | |
ExtensionPublisherName, | |
ExtensionVersion, | |
ExtensionLastPublished | |
) | |
VALUES( | |
'$($extension.extensionId)', | |
'$($extName)', | |
'$($extPublisherName)', | |
'$($extension.version)', | |
CONVERT(DATETIME,SUBSTRING('$($extension.lastPublished)',1,19),127) | |
)" | |
Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment