PowerCLI install script

Posted June 11, 2018

Last updated February 23, 2019 | 2c29b4f


3 minute read

Credit for this information should go to Kyle Ruddy’s post on the VMware Blogs platform. I have just packaged it up into a PowerShell script for ease of deployment.

Currently, this has been tested as of 6/11/2018, and is confirmed working on 64 bit Windows 10 builds 1709 and 1803 (which have PowerShell version 5). PowerCLI is running at 10.1.0 at the current date.

Below is a paste of the script hosted on this site. Feel free to either copy and paste or download from the site and execute.

 Note: Be sure to read the disclaimer before running any of the commands or scripts below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
### Variable definitions

$downloadsFolder = [Environment]::GetFolderPath("Desktop")

$psModulesFolder = [Environment]::GetFolderPath("mydocuments")

$powerCliExists = Test-Path -LiteralPath "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\"

###

### Check for old versions of PowerCLI

If ($powerCliExists -eq $False) {
    Write-Host ""
    Write-Host " No prior versions of PowerCLI detected " -ForegroundColor Black -BackgroundColor Green
    Write-Host ""
}
Else {
    Write-Host ""
    Write-Host " Please remove prior installs of PowerCLI before continuing. Re-run script when this is deleted. " -ForegroundColor Black -BackgroundColor Red
    Write-Host ""
    Exit
}

###

### Grab files for offline install

New-Item -ItemType directory -Path $downloadsFolder\PowerCLI-install >$null

Write-Host ""
Write-Host "Respond with 'y' at the next step when prompted to allow downloading from NuGet. . ."
Write-Host ""

Save-Module -Name VMware.PowerCLI -Path $downloadsFolder\PowerCLI-install

###

### Copy files to modules folder

Copy-Item -Path "$downloadsFolder\PowerCLI-install\*" -Destination "$psModulesFolder\WindowsPowerShell\Modules" -Recurse -Force

###

### Cleanup

Remove-Item -Path "$downloadsFolder\PowerCLI-install" -Recurse -Force

###

###

Write-Host " Installation is complete! " -ForegroundColor Black -BackgroundColor Green
Write-Host " You may need to restart any programs to use the new modules. " -ForegroundColor Black -BackgroundColor Green

###

After this is done, wherever your computer’s Documents folder is (usually C:\Users\USERNAME\Documents), check for a new folder called WindowsPowerShell, and the Modules subfolder should contain some VMware.XXX folders, these should be the PowerCLI modules.

The PowerCLI modules in the WindowsPowerShell folder

The PowerCLI modules in the WindowsPowerShell folder

You’re now ready to rock with the latest version of PowerCLI!