Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell script to download DevOps Extensions from the marketplace as a local file
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string] $Publisher,
[Parameter(Mandatory = $true)]
[string] $ExtensionName,
[Parameter(Mandatory = $true)]
[ValidateScript( {
If ($_ -match "^([0-9].[0-9].[0-9])") {
$True
}
else {
Throw "$_ is not a valid version number. Version can only contain digits"
}
})]
[string] $Version,
[Parameter(Mandatory = $true)]
[string] $OutputLocation
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Write-Output "Publisher: $($Publisher)"
Write-Output "Extension name: $($ExtensionName)"
Write-Output "Version: $($Version)"
Write-Output "Output location $($OutputLocation)"
$baseUrl = "https://$($Publisher).gallery.vsassets.io/_apis/public/gallery/publisher/$($Publisher)/extension/$($ExtensionName)/$($Version)/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
$outputFile = "$($Publisher)-$($ExtensionName)-$($Version).visx"
if (Test-Path $OutputLocation) {
try {
Write-Output "Retrieving extension..."
[uri]::EscapeUriString($baseUrl) | Out-Null
Invoke-WebRequest -Uri $baseUrl -OutFile "$OutputLocation\$outputFile"
}
catch {
Write-Error "Unable to find the extension in the marketplace"
}
}
else {
Write-Output "The Path $($OutputLocation) does not exist"
}
@azurekid

This comment has been minimized.

Copy link
Owner Author

azurekid commented Jan 2, 2020

Download DevOps extensions

This PowerShell script can be used to download a .visx file from the Visual Studio Marketplace to a local machine
The required properties for downloading the .visx file can be found in the URL and properties of the extension.

The first part of the URL shows the publisher and the second part the name of the extension file

image

The version number can be found in the properties field under more info:

image

Usage

Get-Extension -Publisher 'gep13' -ExtensionName 'chocolatey-azuredevops' -Version '0.2.0' -OutputLocation 'C:\Users\Azurekid'

Get-Extensions `
    -Publisher <publishername> `
    -ExtensionName <displayname of the extension> `
    -Version <specific version> `
    -OutputLocation <Path to save the file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.