Windows 10/11 – VMware PowerCLI Installation and Configuration¶
Overview¶
Installing and Configuring VMware PowerCLI to build a custom image using ImageBuilder on a Windows 10/11 workstation. With PowerCLI version 13.1 and greater there is no longer a requirement to install Python 3.7.9. The new requirement is Python 3.7.1 or greater.
Below are the five required steps, with links.
The required configuration steps.
Install VMware PowerCLI¶
Install VMware PowerCLI, which is set of scripts that run inside PowerShell from VMware.
Install PowerCLI¶
Open PowerShell on your workstation.
To install all PowerCLI modules, run the command:
Install-Module VMware.PowerCLI -Scope CurrentUser
Note
If you see a warning that you are installing modules from an untrusted repository, press y and then press Enter to confirm the installation.
List PowerCLI Modules¶
To list version and path for PowerCLI and ImageBuilder modules, run the command:
Get-Module -ListAvailable -name VMware.PowerCLI,VMware.ImageBuilder | select name,path,version | Format-List
Name : VMware.ImageBuilder
Path : C:\Users\username\OneDrive\Documents\WindowsPowerShell\Modules\VMware.ImageBuilder\8.0.0.21610262\VMware.ImageBuilder.psd1
Version : 8.0.0.21610262
Name : VMware.PowerCLI
Path : C:\Users\username\OneDrive\Documents\WindowsPowerShell\Modules\VMware.PowerCLI\13.1.0.21624340\VMware.PowerCLI.psd1
Version : 13.1.0.21624340
PowerShell script ExecutionPolicy¶
To run VMware PowerCLI scripts the execution policies needs to be set. The default execution policy for Windows client computers is Restricted. Restricted means do not load configuration files or run scripts. There are two parameters for the execution policy, the acceptable execution policy and the scope.
Personally, I use Scope ExecutionPolicy Unrestricted and CurrentUser. Loads all configuration files and runs all scripts for my username. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs).
List Execution Policy¶
To list the current execution policies for each scope in the order of precedence, run the command:
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Restricted
LocalMachine Undefined
ExecutionPolicy
Specifies the execution policy. If there are no Group Policies and each scope’s execution policy is set to Undefined, then Restricted becomes the effective policy for all users.
The acceptable execution policy values are as follows:
AllSigned - Requires that all scripts and configuration files are signed by a trusted publisher, including scripts written on the local computer.
Bypass - Nothing is blocked and there are no warnings or prompts.
Default - Sets the default execution policy. Restricted for Windows clients or RemoteSigned for Windows servers.
RemoteSigned - Requires that all scripts and configuration files downloaded from the Internet are signed by a trusted publisher. The default execution policy for Windows server computers.
Restricted - Doesn’t load configuration files or run scripts. The default execution policy for Windows client computers.
Undefined - No execution policy is set for the scope. Removes an assigned execution policy from a scope that is not set by a Group Policy. If the execution policy in all scopes is Undefined, the effective execution policy is Restricted.
Unrestricted - Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
Scope
Specifies the scope that is affected by an execution policy. The default scope is LocalMachine.
The effective execution policy is determined by the order of precedence as follows:
MachinePolicy - Set by a Group Policy for all users of the computer.
UserPolicy - Set by a Group Policy for the current user of the computer.
Process - Affects only the current PowerShell session.
CurrentUser - Affects only the current user.
LocalMachine - Default scope that affects all users of the computer.
Set Execution Policy¶
To set and list the execution policy, run the commands:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Unrestricted
LocalMachine Undefined
Installing Python3¶
To use VMware ImageBuilder module Python 3.7.1 or greater is required. The two most common ways to install Python 3 are from Python.org Downloads and the Microsoft Market Store. You should only choose one medthod not both.
Installing Python3 From Microsoft Store¶
This is my preferred method since it installs the package and sets up the PATH when installing.
If Python3 is not installed on the workstation open Powershell and type python it will open Microsoft Store to install the latest stable version on Python3.
or
To install Python 3.11 open the Microsoft Store app and search for Python, click on Python 3.11. This will install the latest stable version of 3.11, which is Python 3.11.3 at the time on this writing
Test Python 3.11 installation¶
To test the installation, open PowerShell on your workstation, run this command:
python3
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Note
To quit the python shell use quit() or Ctrl-Z plus Enter key to exit
Install Required Python Modules¶
To build ESXi images using VMware ImageBuilder you need to install six psutil lxml pyopenssl python 3.7 modules.
Open a new PowerShell session.
First upgrade pip3, this is good practice before installing new Python modules.
To upgrade pip3, run this command:
python3 -m pip install pip --upgrade
To install required Python modules, run this command:
python3 -m pip install six psutil lxml pyopenssl --upgrade
To list the required modules and their version, run this command:
python3 -m pip list | Select-String -Pattern 'six|psutil|lxml|pyopenssl'
lxml 4.9.2
psutil 5.9.5
pyOpenSSL 23.1.1
six 1.16.0
Set the Python path for VMware PowerCLI¶
First you need to get the Python executable PATH this is needed to set the PATH.
To get the executable PATH, run this command:
cmd /c where python3
C:\Users\username\AppData\Local\Microsoft\WindowsApps\python3.exe
Verify you have the execution policy to run the command:
Get-ExecutionPolicy
Unrestricted
If the output doesn’t show one of the following, Bypass, RemoteSigned or Unrestricted. Click here to set Set Execution Policy.
To set the VMwareCLI Python path replace the PATH with the results from the get executable PATH above, run the command:
Set-PowerCLIConfiguration -PythonPath $HOME\AppData\Local\Microsoft\WindowsApps\python3.exe -Scope User
To list the VMware PowerCLI Python PATH, run this command:
Get-PowerCLIConfiguration -scope Session | select PythonPath
PythonPath
----------
C:\Users\username\AppData\Local\Microsoft\WindowsApps\python3.exe
Install Python 3.7.9 From python.org Downloads¶
Second option for install Python3, Do not do this if you already have Python 3.7.1 or higher installed from the Microsoft Store.
To install click on this link. Python 3.7.9 Windows x86-64 installer
To test you need to first find the path where it was installed, since installing this way there is no PATH to the executable.
Get Executable Path¶
To find the executable path open PowerShell on your workstation, run this command:
Get-ItemProperty -Path HKCU:\SOFTWARE\Python\PythonCore\3.7\InstallPath\ |select ExecutablePath
ExecutablePath
--------------
C:\Users\John Doe\AppData\Local\Programs\Python\Python37\python.exe
When installing from python.org Downloads you need to enter the full path.
Test Python 3.7.9 installation¶
To test the installation, open PowerShell on your workstation and copy the ExecutablePath from the previous command.
& $HOME\AppData\Local\Programs\Python\Python37\python.exe
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Note
To quit the python shell use quit() or Ctrl-Z plus Enter key to exit
Install Required Python Modules¶
To build ESXi images using VMware ImageBuilder you need to install six psutil lxml pyopenssl python 3.7 modules.
First upgrade pip3.7.
Upgrade pip3.7, this is good practice before installing new Python modules.
& $HOME\AppData\Local\Programs\Python\Python37\python.exe -m pip install pip --upgrade
To install required Python modules, run this command:
& $HOME\AppData\Local\Programs\Python\Python37\python.exe -m pip install six psutil lxml pyopenssl --upgrade
To list installed required modules and their version, run this command:
& $HOME\AppData\Local\Programs\Python\Python37\python.exe -m pip list | Select-String -Pattern 'six|psutil|lxml|pyopenssl'
lxml 4.9.2
psutil 5.9.5
pyOpenSSL 23.1.1
six 1.16.0
Set the Python path for VMware PowerCLI¶
Verify you have the execution policy to run the command:
Get-ExecutionPolicy
Unrestricted
If the output doesn’t show one of the following, Bypass, RemoteSigned or Unrestricted. Click here to set Set Execution Policy.
To set the VMwareCLI Python path replace the PATH with the results from the get executable PATH above, run the command:
Set-PowerCLIConfiguration -PythonPath $env:USERPROFILE\AppData\Local\Programs\Python\Python37\python.exe -Scope User
To list the VMware PowerCLI Python PATH, run this command:
Get-PowerCLIConfiguration -scope Session | select PythonPath
PythonPath
----------
C:\Users\John Doe\AppData\Local\Programs\Python\Python37\python.exe