PowerShell modules allow you to easily extend the capabilities of PowerShell by bundling together various cmdlets, functions, variables, etc., into a single package. Modules are incredibly useful for automating administrative tasks, scripting workflows, and boosting your productivity as a system administrator.
While most PowerShell modules are distributed via the online PowerShell Gallery repository, sometimes you may need to set up a module while working in an isolated offline environment with no internet connectivity. Offline PowerShell module installation comes up often when dealing with secured environments like government agencies or financial institutions.
In this comprehensive guide, we will explore step-by-step methods to install a PowerShell module in offline mode from a .nupkg file or extracted folder structure. Whether you are a beginner or an experienced PowerShell scripter, this guide aims to provide detailed instructions to suit all levels.
Table of contents
- Prerequisites
- Method 1 – Install a Module from .nupkg
- Step 1: Download the .NUPKG package
- Step 2: Create the trusted local repository (If it’s not created already)
- Step 3: Transfer Module Packages
- Step 4: Install the Module from the Local Folder
- Updating and Removing Modules
- Method 2 – Install Module Manually from Extracted Folder
- Step 1: Download the Module to a computer with an Internet Connection
- Step 2: Transfer the Modules to the Offline Computer
- Conclusion
Prerequisites
Before diving into the offline installation process, let us first cover some prerequisites:
- Access to a computer with an internet connection to download module packages
- PowerShell 5.1 or later installed on both computers
- USB/Network connectivity between source and destination computers to copy offline packages
- Administrative access to install modules on the offline computer
Now that all prerequisites are met, let us move on to the actual offline installation process.
Method 1 – Install a Module from .nupkg
This method works for all PowerShell modules such as SharePoint Online, Azure AD, Active Directory, Exchange Online, Microsoft Teams, SQL server, PnP, etc. You need to first download the actual PowerShell module file onto the target offline system. Ensure the compressed .nupkg file is available on the target offline system where you wish to install the module. Copy it over to that system using a USB drive if needed.
The key steps to install nupkg in PowerShell:
- Find and download the module
.nupkg
packages from an online computer - Transfer them to your offline computer via USB or network share
- Install the module with
Install-Module
to install each module from the local.nupkg
files
Step 1: Download the .NUPKG package
The NuGet package format is most commonly used to distribute modules via repositories like the PowerShell Gallery.
- Open the PowerShell Gallery, https://www.powershellgallery.com, and search for the specific PowerShell module, such as SQL Server, Microsoft Teams, etc.
- Download the .nupkg file for the PowerShell module from the PowerShell Gallery.
Step 2: Create the trusted local repository (If it’s not created already)
As a next step, We need to register a local folder as a trusted repository. To get a list of existing trusted module repositories, type:
Get-PSRepository
This will get you the trusted repositories for your PowerShell environment.
Create a new folder for the local repository and register it. This is where you’ll be copying your Nupkg files.
Register-PSRepository -Name LocalPackages -SourceLocation C:\NuPkg -InstallationPolicy Trusted
Step 3: Transfer Module Packages
Once you have gathered all the necessary PowerShell module .nupkg
files, you need to transfer them to your offline computer’s local repository you created/identified in the previous step. Copying files can be done using a USB drive or by copying them to a shared network location that the offline machine can access.
Step 4: Install the Module from the Local Folder
As a final step, install a module directly from a .nupkg file without any internet access:
- Start PowerShell with elevated user rights on the offline system (Run as Administrator)
- Navigate to the folder location containing the .nupkg file
- Run the Install-module cmdlet to install the module from the local .nupkg file:
Install-Module SQLServer -Scope AllUsers -Force
The cmdlet will install all module contents and dependencies on your local system, placing the module files appropriately:
You can also use the Install-Package cmdlet:
Install-Package -Name <ModuleName> -Source <repository-path> # For example:PS C:\>Install-Package -Name SQLServer -Source "C:\NuPkg"
- Confirm the installation: After installation, confirm import and functionality:
Get-Module SQLServerGet-Command -Module <ModuleName>
This approach provides an easy PowerShell-centric way to install modules without the internet if you already have the .nupkg file.
Updating and Removing Modules
To update or remove modules installed offline, download the updated packages to your offline computer and re-run the Install-Package
command to install the newer version or the Uninstall-Package
command to remove it.
Method 2 – Install Module Manually from Extracted Folder
Alternatively, if you have the module contents available with you as a zipped folder or extracted files layout, you can choose to install the PowerShell module manually.
In short, download the module from the PowerShell Gallery using an internet-connected computer and transfer the files to the offline machine using a secure method to the module directory.
Step 1: Download the Module to a computer with an Internet Connection
When we need to install PowerShell modules offline, it’s crucial that we initially find and download the correct versions along with their dependencies from an online source. Let’s examine how we can use Find-Module
to locate these modules and Save-Module
to download them for offline use.
Follow these steps for manual installation from extracted module folders:
- Start PowerShell with elevated rights on a system that has an internet connection
- Find the module from the PowerShell gallery
Find-Module -Name SQLServer
- Download the module to a specified folder, using the “Save-Module” cmdlet. In the example, I specified the destination as “C:\Temp”
Save-Module -Name SQLServer -Path "C:\Temp"
This will download all the exported cmdlets and functions to a subfolder in a specified directory.
Step 2: Transfer the Modules to the Offline Computer
To begin with, it’s imperative to place the downloaded module into an appropriate directory recognized by PowerShell. Copy the downloaded Folder (in this case, “SQLServer” in “C:\Temp”) to the target computer’s Folder: “C:\Program Files\WindowsPowerShell\Modules“.
Restart the PowerShell console, and you’ll be able to use the cmdlets of the particular module.
While manual installation takes more effort, it provides flexibility when you have a set of loose module folders. The folder structure can be recreated appropriately under the central module location.
In this article, you learned two different methods to install PowerShell modules in offline mode without internet connectivity. By using the Package Management tools or manually moving the module contents, you can now easily set up modules for isolated environments.
The key things to ensure are that you have the PowerShell module contents locally available as either a .nupkg file or extracted folders, the latest PowerShell version, and an appropriate script execution policy.
When working with systems that lack direct internet access, updating or installing PowerShell modules can be a challenge. As you can see, offline module deployment may need some additional effort, but it is quite achievable. This allows your automation scripts and tools to be made independent of internet connectivity constraints when working in secured environments.
So, next time you need to use that utility PowerShell module on an isolated network, don’t let the lack of internet access stop you! Just use one of these offline installation techniques to turbocharge your PowerShell scripts with powerful modules.
How can I install a PowerShell module on a machine without an internet connection?
To install a PowerShell module offline, you need to download the module from the PowerShell Gallery using an internet-connected computer, transfer the files to the offline machine using a secure method, and then use ‘Import-Module’ to install it on the target computer.
Why would I need to install PowerShell modules offline?
Offline installation is necessary in secure environments where computers cannot connect to the internet, on isolated networks, or in scenarios where security protocols prevent direct downloads from the PowerShell Gallery.
What are the prerequisites for offline installation of PowerShell modules?
You need a version of PowerShell 5.1 or newer, the PowerShellGet and PackageManagement tools, and administrative privileges on the computer where you will be installing the module.
What cmdlet can I use to download a PowerShell module for offline installation?
You can use the ‘Save-Module’ cmdlet to download the module you need from the PowerShell Gallery onto an internet-connected computer.
How should I transfer the downloaded PowerShell module to an offline computer?
Transfer the module using a secure method such as a USB drive or a secure network share, ensuring you follow best practices for file security and integrity.
How can I adjust the execution policy to allow offline PowerShell module installation?
Use the ‘Set-ExecutionPolicy’ cmdlet to change the execution policy settings, allowing for the installation and use of modules that have been downloaded off the internet.
How do I verify that a PowerShell module has been successfully installed offline?
Run ‘Get-Module -ListAvailable’ to list installed modules and try executing cmdlets from the module to ensure it is functioning correctly.
How do I install and import a PowerShell module on an offline machine?
With your PowerShell module copied to ‘C:\Program Files\WindowsPowerShell\Modules’, you could use ‘Import-Module -Name ModuleName’ to import the module into your PowerShell session. Replace ‘ModuleName’ with the actual name of the module’s folder.