Powershell

How to Download Packages from PowerShell Gallery

The PowerShell Gallery serves as a central hub housing a vast collection of PowerShell content, containing scripts, modules, and DSC resources crafted by both Microsoft and the thriving PowerShell community. You can use the PowerShellGet module to discover, install, update, and publish packages from the PowerShell Gallery.

Prerequisites For Downloading the Packages from PowerShell Gallery

Before you can download packages from the PowerShell Gallery for inspection, you need to have the following prerequisites:

A Windows computer with PowerShell 5.0 or higher, or a Linux or macOS computer with PowerShell Core 6.0 or higher. You can check the version of your PowerShellGet module by running:

Get-Module -Name PowerShellGet -ListAvailable

If you need to update your PowerShellGet module, you can run:

Install-Module -Name PowerShellGet -Force -AllowClobber

How to Download Packages from PowerShell Gallery

The Save-Module and Save-Script cmdlets download and save a package from the PowerShell Gallery to a specified path on your computer without installing it. Here is the syntax for the command to find the respective module in PowerShell Gallery:

Find-Module -Name <modulde-name>

Now once you have found the respective module in the PowerShell gallery then to download it follow the below given syntax:

Save-Module -Name <module-name> -Path <save-directory-path-for-module>

For example, if you want to download and inspect a module called PSWindowsUpdate, which allows you to manage Windows updates from PowerShell. First find the PSWindowsUpdate module in the PowerShell Gallery and for that execute:

Find-Module -Name PSWindowsUpdate

Now download and save the PSWindowsUpdate module from the PowerShell Gallery to a local folder

Save-Module -Name PSWindowsUpdate -Path C:\users

Now you can verify that the module is saved in the given directory by navigating to that directory through Windows explorer:

Similarly, if you want to download and inspect a script called Get-WindowsAutoPilotInfo, which retrieves information about Windows updates on your computer, find the Get-WindowsAutoPilotInfo script in the PowerShell Gallery using:

Find-Script -Name Get-WindowsAutoInfo

Now download and save the Get-WindowsAutoPilotInfo script from the PowerShell Gallery to a local folder using:

Save-Script -Name Get-WindowsAutoPilotInfo -Path C:\users

Now you can verify that the script is saved in the given directory by navigating to that directory and executing the ls command:

Conclusion

To download packages from the PowerShell Gallery for inspection use the PowerShellGet module. Use the cmdlets like Save-Script or Save-Module, depending on the package type, to download a package from the gallery for inspection. This will save the package locally without installing it, so you can inspect the package contents.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.