Steps To Install VMware PowerCLI Tools on macOS. VMware PowerCLI is a powerful command-line tool for automating tasks in a VMware virtual environment. With PowerCLI, you can automate tasks such as provisioning virtual machines, managing virtual networks, and more. PowerCLI is available for Windows, Linux, and macOS. In this article, we’ll walk you through the process of installing PowerCLI on a macOS machine.
VMware PowerCLI is built on top of Windows PowerShell and provides a set of PowerShell modules for managing VMware products, such as vSphere, vCloud Director, and NSX-T. With PowerCLI, you can automate tasks, manage large-scale environments, and integrate with other systems and tools, such as Microsoft Active Directory and cloud platforms.
VMware PowerCLI is available for Windows, Linux, and macOS and can be easily installed on those platforms. Once installed, you can use PowerCLI to perform various tasks, such as creating and managing virtual machines, managing virtual networks, and more.
Overall, VMware PowerCLI is an essential tool for automating tasks in a VMware virtual environment, making it easier to manage large-scale environments and streamlining daily tasks for system administrators and DevOps engineers.
Prerequisites
Before you begin, make sure that you have the following software installed on your macOS machine:
- PowerShell 6.x or higher
- .NET Core 3.1 or higher
You can check the version of PowerShell and .NET Core installed on your machine by running the following commands in a terminal window:
Install Homebrew on macOS
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Confirm installation was successful by checking the version:
$ brew --version
Homebrew 3.6.3
Homebrew/homebrew-core (git revision cbc3731cfcd; last commit 2022-09-29)
Homebrew/homebrew-cask (git revision c41e6a96ba; last commit 2022-09-29)
Install PowerShell on macOS
With the Homebrew package installed, we’ll use it to get PowerShell on macOS.
$ brew install --cask powershell
==> Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.2.6/powershell-7.2.6-osx-x64.pkg
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/49609581/83411cda-c621-4bfd-bc39-7668321cbc45?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA
######################################################################## 100.0%
==> Installing dependencies: openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.0.5
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:c4de05580e98de88ece952f04d2ea019d89043379d44a18970cf4a1e9d93c825
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:c4de05580e98de88ece952f04d2ea019d89043379d44a18970cf4a1e9d93c825?se=2022-09-29T19%3A40%3A00Z&sig=lo9lADMAkHz0GxIH
######################################################################## 100.0%
==> Installing openssl@3
==> Pouring [email protected]
🍺 /usr/local/Cellar/openssl@3/3.0.5: 6,444 files, 28.2MB
==> Installing Cask powershell
==> Running installer for powershell; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
Password:
installer: Package name is PowerShell - 7.2.6
installer: Installing at base path /
installer: The install was successful.
🍺 powershell was successfully installed!
Verify that your installation is working properly:
$ pwsh
PowerShell 7.2.6
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /Users/jkmutai/Desktop>
You can get a newer version of PowerShell by updating Homebrew’s formulae and upgrading PowerShell:
brew update
brew upgrade powershell --cask
Install VMware PowerCLI Tools on macOS
Open PowerShell on your macOS workstation.
$ pwsh
Then run the commands in PowerShell to install all PowerCLI modules:
PS /Users/jkmutai> Install-Module VMware.PowerCLI -Scope CurrentUser
You may get a warning relating to modules installation from an untrusted repository, press Y or A to confirm the installation.
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to
install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
The modules are downloaded automatically and stored in the correct folder. The -Scope parameter can be used to make the PowerCLI modules available to AllUsers.
PS /Users/jkmutai> Install-Module VMware.PowerCLI -Scope AllUsers
To list all available modules, run:
Get-Module -ListAvailable
On macOS the modules are stored inside ~/.local/share/powershell/Modules
directory.
$ ls ~/.local/share/powershell/Modules
VMware.CloudServices VMware.Sdk.vSphere.Content VMware.Sdk.vSphere.vCenter.TrustedInfrastructure
VMware.DeployAutomation VMware.Sdk.vSphere.ContentLibrary VMware.Sdk.vSphere.vCenter.VCHA
VMware.ImageBuilder VMware.Sdk.vSphere.Esx.Hcl VMware.Sdk.vSphere.vCenter.Vm
VMware.PowerCLI VMware.Sdk.vSphere.Esx.Hosts VMware.Sdk.vSphere.vCenter.VmTemplate
VMware.PowerCLI.Sdk VMware.Sdk.vSphere.Esx.Settings VMware.Sdk.vSphere.vStats
VMware.PowerCLI.Sdk.Types VMware.Sdk.vSphere.VAPI.Metadata VMware.Sdk.vSphereRuntime
VMware.PowerCLI.VCenter VMware.Sdk.vSphere.vCenter VMware.Vim
VMware.PowerCLI.VCenter.Types.ApplianceService VMware.Sdk.vSphere.vCenter.Authentication VMware.VimAutomation.Cis.Core
VMware.PowerCLI.VCenter.Types.CertificateManagement VMware.Sdk.vSphere.vCenter.CertManagement VMware.VimAutomation.Cloud
VMware.Sdk.Nsx.Policy VMware.Sdk.vSphere.vCenter.Content VMware.VimAutomation.Common
VMware.Sdk.Runtime VMware.Sdk.vSphere.vCenter.Datastore VMware.VimAutomation.Core
VMware.Sdk.vSphere VMware.Sdk.vSphere.vCenter.Deployment VMware.VimAutomation.Hcx
VMware.Sdk.vSphere.Appliance VMware.Sdk.vSphere.vCenter.Guest VMware.VimAutomation.HorizonView
VMware.Sdk.vSphere.Appliance.Access VMware.Sdk.vSphere.vCenter.ISO VMware.VimAutomation.License
VMware.Sdk.vSphere.Appliance.Health VMware.Sdk.vSphere.vCenter.Identity VMware.VimAutomation.Nsxt
VMware.Sdk.vSphere.Appliance.InfraProfile VMware.Sdk.vSphere.vCenter.Inventory VMware.VimAutomation.Sdk
VMware.Sdk.vSphere.Appliance.LocalAccounts VMware.Sdk.vSphere.vCenter.LCM VMware.VimAutomation.Security
VMware.Sdk.vSphere.Appliance.Logging VMware.Sdk.vSphere.vCenter.NamespaceManagement VMware.VimAutomation.Srm
VMware.Sdk.vSphere.Appliance.Networking VMware.Sdk.vSphere.vCenter.Namespaces VMware.VimAutomation.Storage
VMware.Sdk.vSphere.Appliance.Recovery VMware.Sdk.vSphere.vCenter.OVF VMware.VimAutomation.StorageUtility
VMware.Sdk.vSphere.Appliance.SupportBundle VMware.Sdk.vSphere.vCenter.Services VMware.VimAutomation.Vds
VMware.Sdk.vSphere.Appliance.System VMware.Sdk.vSphere.vCenter.Storage VMware.VimAutomation.Vmc
VMware.Sdk.vSphere.Appliance.Update VMware.Sdk.vSphere.vCenter.SystemConfig VMware.VimAutomation.WorkloadManagement
VMware.Sdk.vSphere.Cis VMware.Sdk.vSphere.vCenter.Tagging VMware.VimAutomation.vROps
VMware.Sdk.vSphere.Cis.Tagging VMware.Sdk.vSphere.vCenter.Topology VMware.VumAutomation
PowerCLI usage example
Let’s consider a simple example on using VMware vSphere cmdlets for automated administration of the vSphere environment.
To get details about installed version of PowerCLI, use:
PS /Users/jkmutai> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware.PowerCLI 12.7.0 build 20091289
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.7 build 20067789
VMware Cis Core PowerCLI Component PowerCLI Component 12.6 build 19601368
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.7 build 20091293
PS /Users/jkmutai>
See current configuration before you proceed.
PS /Users/jkmutai>Get-PowerCLIConfiguration
Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout
Seconds
----- ----------- ------------------- ------------------------ -------------------------- -------------------
Session UseSystemProxy Multiple Unset True 300
User
AllUsers
Update the configuration to ignore accept self-signed certificates for SSL connection:
PS /Users/jkmutai> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Perform operation?
Performing operation 'Update VMware.PowerCLI configuration.'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout
Seconds
----- ----------- ------------------- ------------------------ -------------------------- -------------------
Session UseSystemProxy Multiple Ignore True 300
User Ignore
AllUsers
Connect to Environment
Use the Connect-VIServer command to setup a new connection. This will ask you to input username and password.
PS /Users/jkmutai> Connect-VIServer -Server esxi01.example.com -Protocol https
Specify Credential
Please specify server credential
User: root
Password for user root: **********
Name Port User
---- ---- ----
esxi01.example.com 443 root
For non-interactive connection you can pass the username and password in CLI:
Connect-VIServer -Server <ServerIP_or_Hostname> -Protocol https -User <Username> -Password <Password>
Run a cmdlet to retrieve the datastores available.
PS /Users/jkmutai> Get-Datastore
Name FreeSpaceGB CapacityGB
---- ----------- ----------
datastore1 317.590 319.000
You can search for cmdlets commands using regex inPowerCLI, example:
#Show all cmdlets with keyword switch it its name
PS /Users/jkmutai> Get-VICommand *switch
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Export-VDSwitch 12.7.0.20… VMware.VimAutomation.Vds
Cmdlet Get-VDSwitch 12.7.0.20… VMware.VimAutomation.Vds
Cmdlet Get-VirtualSwitch 12.7.0.20… VMware.VimAutomation.Core
Cmdlet Initialize-CpuCoreConfigForEnhancedNetworkingStac… 4.0.0.200… VMware.Sdk.Nsx.Policy
Cmdlet Initialize-PreconfiguredHostSwitch 4.0.0.200… VMware.Sdk.Nsx.Policy
Cmdlet Initialize-RealizedLogicalSwitch 4.0.0.200… VMware.Sdk.Nsx.Policy
Cmdlet Initialize-StandardHostSwitch 4.0.0.200… VMware.Sdk.Nsx.Policy
Cmdlet New-VDSwitch 12.7.0.20… VMware.VimAutomation.Vds
Cmdlet New-VirtualSwitch 12.7.0.20… VMware.VimAutomation.Core
Cmdlet Remove-VDSwitch 12.7.0.20… VMware.VimAutomation.Vds
Cmdlet Remove-VirtualSwitch 12.7.0.20… VMware.VimAutomation.Core
Cmdlet Set-VDSwitch 12.7.0.20… VMware.VimAutomation.Vds
Cmdlet Set-VirtualSwitch 12.7.0.20… VMware.VimAutomation.Core
o verify that PowerCLI is installed correctly, run the following command:
Get-Module VMware.PowerCLI -ListAvailable
You should see the PowerCLI module listed in the output.
Conclusion
Installing VMware PowerCLI on a macOS machine is straightforward and can be completed in just a few steps. With PowerCLI, you can automate a wide range of tasks in a VMware virtual environment, making it an essential tool for system administrators and DevOps engineers.