Run esxcli commands via PowerCli

Quick post on how to run esxcli commands via Powershell.

1 – Use PowerCli to connect to your Host


2 – Save your host as a variable.

$myhost = get-vmhost

3 – Save a variable called $esxcli and use the Get-esxcli cmdlet and reference your newly created host variable as the -VMHost parameter.

$esxcli = Get-EsxCli -VMHost $myhost

4 – Run $esxcli to get a further list of elements that you can explore. Append the element you want to configure or explore to $esxcli.



5 – Once you start seeing methods you can start using these methods to run commands on each element that is focus.



Note: with esxcli via PowerShell you need to put in a value for each option. If you don’t want to set a particular value or leave it as default just use $null

E.G To create a vSwitch you would use this command


The $null value here is for setting the number of ports to be created on vSwitch05. By using the $null Value you enable the default of 128 ports.

If are unsure of what parameter are available for each esxcli command, you can run the command without any options set. It will show you the data type and the parameter that is valid for the command.



Some Valuable Resources to help you on your way

Different Syntax DataTypes – H/T

 [string]    Fixed-length string of Unicode characters
 [char]      A Unicode 16-bit character
 [byte]      An 8-bit unsigned character

 [int]       32-bit signed integer
 [long]      64-bit signed integer
 [bool]      Boolean True/False value

 [decimal]   A 128-bit decimal value
 [single]    Single-precision 32-bit floating point number
 [double]    Double-precision 64-bit floating point number
 [DateTime]  Date and Time

 [xml]       Xml object
 [array]     An array of values
 [hashtable] Hashtable object

A list of all ESXCLI commands albeit for 5.0 – Note that as vSphere versions change the parameters differ as options are added or deprecated.

One thought on “Run esxcli commands via PowerCli

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s