In this post we will be going through using the PowerCLI Get-EsxCli commandlet, which is used to call EsxCli command from PowerShell instead of having to SSH directly to the the ESXi host.
This can be useful when trying to gather information from multiple hosts instead of connecting on to each host with SSH or updating configuration settings.
First step is to connect to vCenter, once connected we can run the Get-EsxCli command and this will return the list of namespaces that can be use to gather information or set configuration settings.
We will be using -V2 as this sets Get-EsxCli to use version 2 interface as version 1 is being deprecated and will be removed in a later version.
Get-EsxCli -VMHost esxihost -V2
We can set the Get-EsxCli command to a variable so that we can call the namespaces, below will call the network namespace, once called there will be a list of addtiaonl namespaces that can be called.
$vmhostesxcli = Get-EsxCli -VMHost esxihost -V2 $vmhostesxcli.network
Once we select a namespace there should also be a list of methods that can be called these can be used to run specific actions like list or get to return information.
To list all nic’s we can call the nic and then list namespace
To gather info on details like driver version we can use the get method, in v1 you use to be able to call the nic name directly but if you try this in v2 the below error will be returned.
If specified, the arguments parameter must contain a single value of type Hashtable.
This is due to the method requiring a hash table parameter. If we call the help method it should return the valid parameters. If the parameter has a hyphens remove this or the command wont work.
For the nic namespace the parameter is nicname and needs to be called as a hash table.
There might be some namespaces that have multiple properties like driverinfo under nic, these can be called by adding the property like below.
Now that we have the command we can start to build out a script to export information.
In this case we will be getting all hosts, listing all NIC’s and getting the drivers info.
The above shows that Get-EsxCli can be very good for retrieving information, if we wanted to set a configuration we can use similar command syntax but use the set method.
In this case we will update the Power policy settings on all host, we could do this manually by going to the Configure > Hardware > Overview > Power Management one each host and update the power policy settings
but doing this on a larger cluster is a lot of effort. To update using PowerCli we can first create the script to report on the current host power policy.
To update the policy settings we will use the set method like the below.
Below are the 4 different power policy’s.
We can then take the above and create a re-usable script to report or set the power policy on all host in one go.
To download a copy of the either of the above script use the below link to my Github these can be used as reference if you want to create your own scripts for other settings.