This article shows how to install a PowerShell Nuget Package, and also deploy the same Module to an Offline PC. Install-PackageProvider cmdlet is the first step so that Nuget can be added as a Package Provider, and the Set-PSRepository cmdlet enables to set PSGallery as a trusted source before running Install-Module.
Table of Contents
Install-PackageProvider
When you have a PC connected to the internet, first you have to add Nuget as a Package Provider by using Install-PackageProvider.
Install-PackageProvider -Name NuGet -Force
Run:
After the run, you can see a folder created under C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208
Search a Nuget Package to Install
As an example, I searched SqlServer modules.
Find-Package SqlServer*
Run:
Install Module
Install-Module cmdlet will install the package.
Install-Module SqlServer
However, you may get the following security pop-up.
In order to avoid the pop-up, the Set-PSRepository cmdlet is added to Trust the Repository.
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module SqlServer
Run:
SqlServer was correctly installed.
Offline .nupkg Installation
Search and download the Nuget Package from PSGallery Web Site.
Copy C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll to exactly same folder path location.
Copy downloaded .nupkg file (sqlserver.21.1.18257-preview.nupkg) to a folder (ex. C:\NuPkg)
Register-PSRepository -Name LocalPackages -SourceLocation C:\NuPkg -InstallationPolicy Trusted
Install-Module SqlServer
You may also be interested in other articles: How to restore VM Snapshot remotely using PowerShell