Run esxcli commands via PowerCli

Quick post on how to run esxcli commands via Powershell.

1 – Use PowerCli to connect to your Host

Connect-VIServer 192.168.101.150

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.

$esxcli.network

esxcli

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

$esxcli.network.nic.list()

nic2

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

$esxcli.network.vswitch.standard.add($null,"vSwitch05")

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.

newvswitch

 

Some Valuable Resources to help you on your way

Different Syntax DataTypes

http://ss64.com/ps/syntax-datatypes.html – 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.

https://rvdnieuwendijk.com/2012/08/19/how-to-list-all-the-powercli-esxcli-commands/

One thought on “Run esxcli commands via PowerCli

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s