Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Last active January 26, 2026 17:52
Show Gist options
  • Select an option

  • Save indented-automation/fce416976b6a3c821658c808fa8506fc to your computer and use it in GitHub Desktop.

Select an option

Save indented-automation/fce416976b6a3c821658c808fa8506fc to your computer and use it in GitHub Desktop.
#Requires -RunAsAdministrator
# This module will be installed by this snippet.
$module = 'Microsoft.PowerShell.PSResourceGet'
# Find the module in the gallery
$params = @{
Uri = 'https://www.powershellgallery.com/api/v2/FindPackagesById()'
Body = @{
'$filter' = 'IsLatestVersion eq true'
id = "'$module'" # Extra quotes are required.
}
}
$searchResult = Invoke-RestMethod @params
# Download the module archive
Invoke-RestMethod $searchResult.content.src -OutFile module.zip
# Expand the archive to a versioned folder.
$params = @{
Path = 'module.zip'
Destination = 'C:\Program Files\WindowsPowerShell\Modules' |
Join-Path -ChildPath $module |
Join-Path -ChildPath $searchResult.properties.version
}
Expand-Archive @params
# Clean up redundant package files.
Get-ChildItem $params.Destination |
Where-Object Name -in @(
'_rels'
'package'
'[Content_Types].xml'
"$module.nuspec"
) |
Remove-Item -Recurse
# Remove downloaded archive
Remove-Item module.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment