Powershell: Transfer Modules to an offline PC

Hi,

in these days powershell modules are often installed from a (NuGet) Repository and not by a Setup program.

In companies may exists computers which does not have an active internet connection.

But how to install the modules on these devices?

It’s possible by simply coping some folders 🙂

In this example I will install the VMware PowerCli Modules

First install the modules on an PC which is similar (OS, Architecture) to the offline PC’s. I’ve already described this process.

Then locate the modules in the filesystem. Powershell has multiple folders where modules are installed to. This “oneliner” list all subfolders under the Powershell module locations:

PS D:\> $env:PSModulePath.Split(";") | %{if(Test-Path $_){get-Item ($_+"\*")}}

    Verzeichnis: C:\Program Files\WindowsPowerShell\Modules


Mode                LastWriteTime         Length Name
...
d-----       22.04.2018     21:54                VMware.VimAutomation.Cloud
d-----       22.04.2018     21:51                VMware.VimAutomation.Common
d-----       22.04.2018     21:52                VMware.VimAutomation.Core
d-----       22.04.2018     21:54                VMware.VimAutomation.HA
...

Find the modules you want to transfer and copy all Modules folders to the new machine in the same folder “C:\Program Files\WindowsPowerShell\Modules”. In this example all folders started with VMware.

When the copy process has finished close all powershell instances at the “offline” PC and reopen it. Powershell reads all module information at startup.

Check if modules are found

PS D:\> Get-Module -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name
---------- -------    ----
...
Script     6.5.2.7... VMware.DeployAutomation
Script     6.5.2.7... VMware.ImageBuilder
Manifest   10.0.0.... VMware.PowerCLI
Script     10.0.0.... VMware.VimAutomation.Cis.Core
Script     10.0.0.... VMware.VimAutomation.Cloud
Script     10.0.0.... VMware.VimAutomation.Common
Script     10.0.0.... VMware.VimAutomation.Core
...

Then try to load the module(s).

PS D:\> Import-Module VMware.PowerCLI

In case of VMware PowerCli and no internet connection is available it can happens that the connect to the vCenter takes a long time and then fails when the Server Certificate cannot verified.

PS D:\> Connect-VIServer yourVcenter.yourDomain.org
Connect-VIServer : 22.04.2018 22:57:59  Connect-VIServer                Error: Invalid server certificate. Use
Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect
once or to add a permanent exception for this server.

If this occures you have no other option as to disable the certificate check.

PS D:\> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope AllUsers -Confirm:$false

Michael

Advertisment to support michlstechblog.info

Time limit is exhausted. Please reload CAPTCHA.

Original Theme by Schiy · Powered by WordPress