Most popular PowerShell modules are installed online from the official PowerShell Gallery (PSGallery) using the Install-Module
command. However, if your computer is in an isolated network without internet access or PSRepository access is restricted, installing PowerShell modules becomes challenging. This article covers offline installation methods for PowerShell modules and their importation from a remote computer, using the SQL Server module as an example.
The PowerShellGallery.com website does not provide direct download links for modules. The only downloadable option is a NuGet package (.nupkg file), but this does not constitute a full module installation (the primary issue being that dependencies are not installed).
Manual Installation of PowerShell Modules in Offline Systems
To install a PowerShell module in an offline environment, you must first download the module on a computer with internet access and then transfer it to the offline computer.
1. Check the PowerShell version on the target computer; it should be at least 5.1:
$PSVersionTable.PSVersion
2. Verify that the desired module is available in PowerShell Gallery:
Find-Module –Name *SqlServer* | Select Name, Version, Repository
3. Download the required module to the computer with internet access:
Save-Module –Name SqlServer –Path C:\ps\
This downloads the SqlServer module to the specified directory.
4. Copy the module folder to the offline computer where you want to install it.
5. Determine the directories where PowerShell stores modules:
$env:PSModulePath -split ";"
You will see the paths where PowerShell stores modules, for example:
– C:\Users\root\Documents\WindowsPowerShell\Modules — modules available only to the current user (CurrentUser scope).
– C:\Program Files\WindowsPowerShell\Modules — path for installing modules for all users on the computer (AllUsers scope).
– C:\Windows\system32\WindowsPowerShell\v1.0\Modules — directory for default built-in modules.
6. Copy the module to the C:\Program Files\WindowsPowerShell\Modules directory.
7. Verify the module’s availability:
Get-Module -Name SQLServer -ListAvailable
8. Check the path where the module is installed:
(Get-Module -ListAvailable SQLServer).path
9. List the commands available in the module:
Get-Command -Module SQLServer
This method can be used to install any module. It is commonly applied for installing the SQLServer, PSWindowsUpdate, and PowerCLI modules for VMware.
Importing a PowerShell Module Over the Network from Another Computer
If you don’t want to install a module on every computer, you can import it from another computer using PSRemoting.
1. Create a PowerShell session with the remote computer:
$session = New-PSSession -ComputerName msk-sql01
2. List the installed modules on the remote computer:
Get-Module -PSSession $session –ListAvailable
3. Import the desired module to your local computer:
Import-Module -PSsession $session -Name SqlServer
4. Close the session after completing your work:
Remove-PSSession $session
Importing Modules via Implicit Remoting
You can use PowerShell cmdlets installed on a remote computer without explicitly installing the module locally.
1. Connect to the remote computer and import the module:
$session = New-PSSession -ComputerName msk-sql01
Invoke-Command {Import-Module SqlServer} -Session $session
2. Export the module’s cmdlets from the remote session to a local module:
Export-PSSession -Session $session -CommandName *-Sql* -OutputModule RemSQLServer -AllowClobber
This creates a new PowerShell module RemSQLServer on your computer (in the directory C:\Program Files\WindowsPowerShell\Modules).
3. Close the session:
Remove-PSSession $session
4. Use the cmdlets by importing the new module:
Import-Module RemSQLServer
The SQL Server module’s cmdlets will be available as long as the PowerShell session remains active.
These methods enable the installation and use of PowerShell modules in offline systems or importing them from another computer, which is particularly useful in environments with limited internet access.