Skip to content

Instantly share code, notes, and snippets.

@vinijmoura
Created August 19, 2021 22:07
Show Gist options
  • Save vinijmoura/3d8abda0965271a962444cfc772a9b9e to your computer and use it in GitHub Desktop.
Save vinijmoura/3d8abda0965271a962444cfc772a9b9e to your computer and use it in GitHub Desktop.
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