How To Install VMware PowerCLI Tools on macOS

Posted on 122 views

VMware PowerCLI is a collection of PowerShell modules that provides cmdlets used to manage VMware environments. As a VMware Virtualization administrator, you’ll be able to perform most vSphere administrative tasks as well as automate many operations. A cmdlet is a lightweight command that PowerShell runtime invokes within the context of automation scripts that are provided at the command line. They are invoked programmatically through PowerShell APIs.

The combination of VMware PowerCLI and PowerShell unlocks the power of automation more and more. PowerCLI provides an integration with VMware products such as vSphere ESXi, NSX, vCenter, vRealize Operations, VSAN, Horizon, and VMware Cloud platforms.

Install VMware PowerCLI Tools on macOS

The major requirement for this installation are:

Install Homebrew on macOS

If you don’t have Homebrew already installed on your system, run the commands below to download it.

/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: [email protected]
==> 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 [email protected]
==> Pouring [email protected]
🍺  /usr/local/Cellar/[email protected]/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  -Protocol https -User  -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

For more understanding on PowerCLI usage, refer to official VMware documentation pages:

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.