Skip to content

Instantly share code, notes, and snippets.

@azurekid
Last active March 20, 2025 20:00
Show Gist options
  • Save azurekid/ca641c47981cf8074aeaf6218bb9eb58 to your computer and use it in GitHub Desktop.
Save azurekid/ca641c47981cf8074aeaf6218bb9eb58 to your computer and use it in GitHub Desktop.
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
Copy link
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>

@paviad
Copy link

paviad commented Jul 18, 2021

The url structure has changed, it is now:

"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${Publisher}/vsextensions/${ExtensionName}/${Version}/vspackage"

@uyriq
Copy link

uyriq commented Jul 13, 2023

Great script, @azurekid! I'd like to thank @paviad for modernizing it. Additionally, to allow for versions in the format of d+.d+.d+ (not just d.d.d), it's a good idea to change line 12 from If ($_ -match "^([0-9].[0-9].[0-9])") { to If ($_ -match "^([0-9]+\.[0-9]+\.[0-9]+)$") {.

I ran the script in Bash using the following command:

pwsh /home/user/scripts/script.ps1 -Publisher "GitHub" -ExtensionName "copilot" -Version "1.96.259" -OutputLocation "/home/user/downloads" 

It worked flawlessly!

@azurekid
Copy link
Author

azurekid commented Jul 14, 2023

https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${Publisher}/vsextensions/${ExtensionName}/${Version}/vspackage

Hi thanks for the feedback, and sorry for not coming back earlier to this.
I have updated the url as you have suggested in your comments but that results in an error message that the package could not be found.

Can you add a PR on you r suggestion, maybe I am doing something wrong ;-)

@azurekid
Copy link
Author

Great script, @azurekid! I'd like to thank @paviad for modernizing it. Additionally, to allow for versions in the format of d+.d+.d+ (not just d.d.d), it's a good idea to change line 12 from If ($_ -match "^([0-9].[0-9].[0-9])") { to If ($_ -match "^([0-9]+\.[0-9]+\.[0-9]+)$") {.

I ran the script in Bash using the following command:

pwsh /home/user/scripts/script.ps1 -Publisher "GitHub" -ExtensionName "copilot" -Version "1.96.259" -OutputLocation "/home/user/downloads" 

It worked flawlessly!

hi @uyriq
It has been quiet a while when I wrote this little script, but happy it still seems to work.
I have added your suggestion to the code

Kind Regards,

Rogier

@l-logan-777
Copy link

I am trying to use this and for whatever reason it keeps giving me the error:
Unable to find the extension in marketplace. Our company started having issues with some of their downloads as well last month.
cmdlet DL_ext3.ps1 at command pipeline position 1
Supply values for the following parameters:
Publisher: Red Hat
ExtensionName: redhat.ansible
Version: 25.2.0
OutputLocation: C:\Users\fm815f
Publisher: Red Hat
Extension name: redhat.ansible
Version: 25.2.0
Output location C:\Users\fm815f
Retrieving extension...
DL_ext3.ps1: Unable to find the extension in the marketplace

Any help would be greatly appreciated. Thanks

@azurekid
Copy link
Author

azurekid commented Mar 8, 2025

I am trying to use this and for whatever reason it keeps giving me the error: Unable to find the extension in marketplace. Our company started having issues with some of their downloads as well last month. cmdlet DL_ext3.ps1 at command pipeline position 1 Supply values for the following parameters: Publisher: Red Hat ExtensionName: redhat.ansible Version: 25.2.0 OutputLocation: C:\Users\fm815f Publisher: Red Hat Extension name: redhat.ansible Version: 25.2.0 Output location C:\Users\fm815f Retrieving extension... DL_ext3.ps1: Unable to find the extension in the marketplace

Any help would be greatly appreciated. Thanks

Hi, and happy weekend @l-logan-777
I will take a look at it and come back to you later this weekend
Can you share something like a screenshot of the error you are getting

@l-logan-777
Copy link

l-logan-777 commented Mar 8, 2025 via email

@azurekid
Copy link
Author

It is quiet some time ago when I wrote this script.
If would like to see any features added, please let me know :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment