Last active
January 26, 2026 17:52
-
-
Save indented-automation/fce416976b6a3c821658c808fa8506fc 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
| #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