This page looks best with JavaScript enabled

PowerCLI: Offline install PowerShell v3 and v4

 ·  ☕ 1 min read  ·  ✍️ Brett Johnson

Today I came across the need to use PowerCLI on a computer without internet access. Thankfully I found this blog post detailing the steps that I needed to perform, however not all was rainbows and unicorns. I quickly ran aground when attempting to import the modules. After a bit of research, I learnt that Microsoft had changed the module directory structure in PowerShell v5. This new structure is not compatible with previous versions.

The Problem

When using Install-Module to install a module, the module files as located in a subdirectory which is the version number. This is not a supported directory structure for PowerShell version 3 and 4. This caused an error when attempting to import, PowerShell could not find the modules.

PowerShell-v5-Module-Structure

PowerShell-v5-Module-Structure

The Solution

The solution to the problem is simple enough, move the module files up one directory. As there are a number of modules this can be tedious. So here’;s a script to do that for you

1
2
3
4
5
6
7
$ModuleFolders = Get-ChildItem VMware*

Foreach($ModuleFolder in $ModuleFolders){
    $VersionFolder = $ModuleFolder | Get-ChildItem -Directory
    $CopySourceString = $VersionFolder.FullName + "\*"
    Copy-Item $CopySourceString $ModuleFolder.FullName -Verbose
}

Further details on the script are available on GitHub.

After running the script, I was able to user PowerCLI for super-secret spy business.

 

Share on

Brett Johnson
WRITTEN BY
Brett Johnson
Automator of things