How to get PowerShellGet working with no Internet access

2 minute read

As most of you know I am a big fan of PowerShell. With Powershell 5.0, we now have PowerShellGet which means it is simple to install modules from the Internet via the Install-Module command.

Install-Module gac

This works great if your computer is directly connected to the Internet and can see the global PowerShell repository.

But what about if your VM is hidden behind a corporate firewall and has very limited or no internet access? This makes it impossible to get the packages as shown below.

First we might want to install a package. Oh… we need to install NuGet as well? No problem. Click Yes!

But since we have no net access, NuGet can’t be installed, so we get a sea of red text.

What can we do?

One option is to create your own NuGet server behind the firewall and download and push packages to that.

There are already some good articles about how to do that.

Once that is set up and you have published some packages to it, you need to register the repository so when you run Install-Module, PowerShell knows to look internally rather than externally.

A sample command for registering a PowerShell Repository is:

Register-PSRepository -Name "LocalPowerShell" -SourceLocation "http://<servername>/nugetpowershell/nuget" -InstallationPolicy Trusted -PackageManagementProvider 'nuget'

But when you run it, you are again prompted to install NuGet, which will still fail due to no Internet access.

So how can we get NuGet installed?

This seems to be the only way that works.(that I have seen!) We can see from the dialog message that it is expecting to be located in one of two folders.

One of them is C:\Program Files\PackageManagement\ProviderAssemblies.

So looking on another computer (that does have Internet access) ensure that the NuGet package is installed and explore that folder, we can see:

So if we copy that DLL over to the VM without internet access, and store it in the same folder structure, this seems to work.

IMPORTANT NOTE: After you copy the DLL over, ensure you restart your PowerShell ISE program!

Time for Take Two

With the DLL in place and ISE restarted, lets run the command again to register the PowerShell repository:

It still seems to give an error! This can be ignored! If we run the command Get-PSRepository we can see it was correctly registered.

Now we can install modules from the local repository with no issues. Awesome!

TIP: If you want to find out what modules are available on any repository, enter Find-Module -Repository <name of local repository>

This was the only way I was able to get this to work on servers with no Internet access. If there is a better way, please let me know!

Leave a comment