This post is deprecated. Please refers to the new version of Get-Esxcli on steroids compatible with V2
Get-EsxCli made easy. 480 PowerCli functions, one for each esxcli command. Take into account all ESXi build from version 5.0 to 6.0
Update 18/10/2015: v2.0.3 – minor update – six ESXi build added and 8 new functions
3086167 – ESXi 5.0 Patch 12
3070626 – ESXi 5.1 Patch 8
3029944 – ESXi 5.5 Update 3
3116895 – ESXi 5.5 Update 3a
3029758 – ESXi 6.0 U1
3073146 – ESXi 6.0 U1a
New functions introduced in vSphere 6 Update 1:
add-vsan.cluster.unicastagent
enable-storage.iofilter
get-vsan.cluster.preferredfaultdomain
list-storage.iofilter
list-vsan.cluster.unicastagent
remove-vsan.cluster.unicastagent
set-storage.core.device.vaai.status
set-vsan.cluster.preferredfaultdomain
New functions introduced in vSphere 5.5 Update 3 (already in vSphere 6):
unmount-vsan.storage.diskgroup
mount-vsan.storage.diskgroup
Update 18/08/2015: v2.0.2 – minor update – one ESXi build added
2809209 – ESXi 6.0.0b
Update 14/06/2015: v2.0.1 – minor update – two ESXi build added
2718055 – ESXi 5.5 Patch 5*
2715440 – ESXi 6.0 Express Patch 2
Update 29/04/2015: Major release 2. And bug fixed for 5 functions
Major version change from 1.0.0 to 2.0.0
The previous approach below was not convenient when working with only one host:
$esxcliOutput = $esxcli.network.vswitch.dvs.vmware.vxlan.get() $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable
The output is now directly the output of the esxcli command:
Return $esxcli.network.vswitch.dvs.vmware.vxlan.get()
It is still possible to create an output including the name of the host AND information from the output of an ESXCLI command.
However it will be necessary to use an approach similar to the one described in this post:
powershell-v4-pipelinevariable-common-parameter
Examples updated for the release 2.0.0:
Test if all hosts connected to a vCenter server can ping a NTP server.
The challenge here is that output of the esxcli command will provide you two CodeProperty “Summary” and “Trace”
$NTPSERVER = “10.0.0.8” Get-VMhost | foreach {($MyHost = $_)} | ping-network.diag -count 2 -host2 $NTPSERVER | Select-Object @{Name="MyHost";expression={$MyHost}} -expand summary | ogv
In the background there was another challenge.
With 5.1 it would have been necessary to use something like:
$esxcli.network.diag.ping(2,$null,$null,“10.0.0.8”,$null,$null,$null,$null,$null,$null,$null,$null)
With 5.5 something like:
$esxcli.network.diag.ping(2,$null,$null,“10.0.0.8”,$null,$null,$null,$null,$null,$null,$null,$null,$null)
This is due to the addition of the “netstack” parameter. The “ping-network.diag” on the other hand will work for all 5.1 and 5.5 hosts.
With the “ping-network.diag” you could also select the outgoing interface in an easy way
ping-network.diag -count 2 -host2 $NTPSERVER -interface 'vmk0'
Instead of updating the previous commands like this
With 5.1:
$esxcli.network.diag.ping(2,$null,$null,“10.0.0.8”,'vmk0',$null,$null,$null,$null,$null,$null,$null)
With 5.5:
$esxcli.network.diag.ping(2,$null,$null,“10.0.0.8”,'vmk0',$null,$null,$null,$null,$null,$null,$null,$null)
Configure HP 3PAR storage claim rules for new hosts in a new cluster “Cluster01”
From the official documentation
esxcli storage nmp satp rule add -s “VMW_SATP_ALUA” -P “VMW_PSP_RR” –O “iops=1” -c “tpgs_on” -V “3PARdata” -M “VV” -e “HP 3PAR Custom Rule”
You will obtain the equivalent for all hosts in a cluster, without enabling SSH, by using:
Get-cluster –name “Cluster01” | get-vmhost | add-storage.nmp.satp.rule –satp "VMW_SATP_ALUA" –psp "VMW_PSP_RR" –pspoption "iops=1" –claimoption "tpgs_on" –vendor "3PARdata" –model "VV" –description "HP 3PAR Custom Rule”
And to check the result
Get-cluster –name “Cluster01” | get-vmhost | foreach {($MyHost = $_)} | list-storage.nmp.satp.rule | Select-Object @{Name="MyHost";expression={$MyHost}},* | Where {$_.Vendor –eq “3PARdata”} | ogv
The inspiration for the next one is coming from a post from Ather Beg, who I had the chance to work with. How to remind yourself of Advanced Settings changes in ESXi.
Original command
esxcli system settings advanced list –d
Now let do this for all hosts connected to vCenter server.
Get-vmhost | foreach {($MyHost = $_)} | list-system.settings.advanced –delta $True | Select-Object @{Name="MyHost";expression={$MyHost}},*| ogv
It is important to notice that the “delta” parameter is not available for all builds. If you were using get-esxcli directly maybe you could have experienced issues due to this.
If your host doesn’t support this parameter, for example with the build “1024429”, the following error will be returned “At least one parameter is not compatible with this ESXi build:1024429” and no esxcli command will be executed.
If you are working with only one host, is it easier to use these functions now, no need to use “-expand esxclioutput” any longer
get-vmhost "MyTestHost" | list-storage.nmp.device | select * | ogv
Update 26/04/2015: Fix issue with “esxcli vmware vxlan commands” and vSphere 6 / 3 new builds / github
For all commands in the vxlan namespace add a new test for all ESXi 6.0 build. Example below:
2494585 { if($esxcli.network.vswitch.dvs.vmware.vxlan){ $esxcliOutput = $esxcli.network.vswitch.dvs.vmware.vxlan.get() $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } Else{ Write-error "This function IS available with this ESXi build:$Build however the host has not been prepared for VXLAN. If the host has been prepared close PowerCli and restart a new session to refresh" }
All functions now compatible with the following builds.
2615704 – ESXi 6.0 Express Patch 1
2638301 – ESXi 5.5 Express Patch 7
2583090 – ESXi 5.1 Patch 7
All functions now stored on github
Update 19/04/2015: Issue with “esxcli vmware vxlan commands” and vSphere 6
I have noticed a little late the information below in the vCLI release note for 6.0
The following ESXCLI commands are no longer included on an ESXi host by default. They become available after the host has been prepared for VXLAN.
esxcli vmware vxlan commands
So if you are planning to use any function in the namespace “esxcli vmware vxlan commands” it will not work with vSphere 6.
I have extracted all commands available by default for ESXi 6.0, but it will be necessary to do the same when the host has been prepared for VXLAN.
Identify all differences between the two set of data extracted.
And the most complicated part, review the logic in all scripts generated and add a condition to take into account when an ESXi 6.0 host has been or has not been prepared for VXLAN.
Update 17/03/2015: All scripts updated for vSphere 6 and two others builds
471 cmdlets now – 64 introduced with vSphere 6
2509828 – ESXi 5.0 Patch 11
2456374 – ESXi 5.5 Express Patch 6
2494585 – ESXi 6.0 GA
Welcome to the Inaugural post of The Crazy Consultant blog.
For this first post, and first script published, the focus will be related to the Get-EsxCi powerCli cmdlet.
You will find a very good introduction for this topic in this post “How to use ESXCLI in PowerCLI” written by Florian Grehl.
The Get-EsxCli cmdlet is very powerful and can let us run esxcli command even if ssh is not allowed for a host.
Unfortunately it is not really user friendly and you may have already experienced in the hard way that some of your own scripts based on this cmdlet have stopped to work after an update of your ESXi hosts.
So I have created 471 cmdlets so far, one for each esxcli function available through Get-Esxcli, which take into account the build of the targeted ESXi hosts.
Download latest release with all functions.
These scripts will be updated as regularly as possible to take into account new Build of ESXi and feedback received.
Example with ping-network.diag
Let’s dig into one of my favourite cmdlet, “ping-network.diag”, which is the equivalent of “esxcli network diag ping” from the command line.
function ping-network.diag{ <# .SYNOPSIS Send ICMP echo requests to network hosts. .DESCRIPTION This function provide access via Power-Cli to the esxcli equivalent function. All parameters and help associated to the original esxcli function are available. This function is based on the original get-esxcli PowerCLI cmdlet... ...and enhance it by taking into account the build of the target ESXi host. A PowerCli VMHost object is a mandatory parameter It is also possible to pipe VMhost objects to execute this function accross many hosts in one operation .NOTES Author: Christophe Calvet Blog: http://www.thecrazyconsultant.com/get-esxcli_on_steroids .LINK This function is part of a package containing a powershell function for each of the esxcli commandGet-EsxCli on steroids V2vSphere Command-Line Interface Reference http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vcli.ref.doc/vcli-right.html Get-Esxcli PowerCLI Reference http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.powercli.cmdletref.doc/Get-EsxCli.html .PARAMETER count Specify the number of packets to send. .PARAMETER debug2 VMKPing debug mode. .PARAMETER df Set DF bit on IPv4 packets. .PARAMETER host2 Specify the host to send packets to. Specify the host to send packets to. This parameter is required when not executing ping in debug mode (-D) .PARAMETER interface Specify the outgoing interface. .PARAMETER interval Set the interval for sending packets in seconds. .PARAMETER ipv4 Ping with ICMPv4 echo requests. .PARAMETER ipv6 Ping with ICMPv6 echo requests. .PARAMETER nexthop Override the system's default route selection, in dotted quad notation. (IPv4 only. Requires interface option) .PARAMETER size Set the payload size of the packets to send. .PARAMETER ttl Set IPv4 Time To Live or IPv6 Hop Limit .PARAMETER wait Set the timeout to wait if no responses are received in seconds. .PARAMETER netstack Specify the TCP/IP netstack which the interface resides on .PARAMETER VMHost One or many PowerCli VMHost object .EXAMPLE Some examples, and all others esxcli/powershell functions, are available in the blog #> param( [System.Nullable[long]]$count, [System.Nullable[boolean]]$debug2, [System.Nullable[boolean]]$df, [string]$host2, [string]$interface, [System.Nullable[long]]$interval, [System.Nullable[boolean]]$ipv4, [System.Nullable[boolean]]$ipv6, [string]$nexthop, [System.Nullable[long]]$size, [System.Nullable[long]]$ttl, [System.Nullable[long]]$wait, [string]$netstack, [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMhost ) process{ If ($host2 -eq ""){ $host2 = [System.Management.Automation.Language.NullString]::Value } If ($interface -eq ""){ $interface = [System.Management.Automation.Language.NullString]::Value } If ($nexthop -eq ""){ $nexthop = [System.Management.Automation.Language.NullString]::Value } If ($netstack -eq ""){ $netstack = [System.Management.Automation.Language.NullString]::Value } Try{ $esxcli = Get-EsxCLI -VMHost $VMhost $BUILD = $VMHost.build switch($BUILD) { 799733 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 838463 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 914609 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1021289 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1065491 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1117900 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1157734 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1312873 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1483097 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1612806 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1743533 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1900470 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 2000251 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 2191751 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 2323236 { If(($netstack -ne $Null)){ Write-error "At least one parameter is not compatible with this ESXi build:$Build " } Else{ $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } } 1331820 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1474528 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1623387 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1746018 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1746974 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1881737 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 1892794 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 2068190 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 2143827 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 2302651 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } 2403361 { $esxcliOutput = $esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait) $FinalTable = New-Object -Type PSObject -Prop ([ordered]@{ "VMHost" = $VMHost; "esxcliOutput" = $esxcliOutput; }) Return $FinalTable } default{ Write-error "This function is not available with this ESXi build:$Build OR has not been tested yet. Please refer to the blog for all build tested and latest version of this script." } } } Catch{ Write-error $_ } } }
Explanation needed maybe?
All scripts follow the same logic.
Line 1: Function Name:
As recommend by Microsoft, a PowerShell cmdlet is supposed to use a verb-noun pair. In order to be as close as possible to this model the following convention will be used:
Verb: The Code Method Name extracted from esxcli. For this example “diag”
Noun: All namespaces associated to this command. For this example “network.diag”
Line 3-4: Synopsis:
Information in the “SYNOPSIS” match the help message of the command in esxcli.
For some functions two or more slightly different “help messages” are present. It means that there are different variations of this help message based on the build of the hosts.
Line 31-69:Parameters help:
For some esxcli command new parameters have been introduced in esxcli from one build to another. This is the case with “netstack” for “esxcli network diag ping” introduced in 5.5.
All parameters available regardless of the build will be available for this cmdlet. It introduces some challenges that will be described very soon.
The help message for each parameter in esxcli has been added.
Similar to the logic in the synopsis, one parameter could have multiple help message depending of the ESXi Build. This is the case here for “host2”.
Maybe you are wondering why host2 is used here instead of the parameter “host” like in esxcli.
The reason is quite simple, “$host” has a meaning in PowerCli. So to avoid any issues “2” has been appended to the parameter name.
3 other “sick” parameters have been identified so far and have received the same special treatment.
Profile / Version / Debug.
There are another case of inconsistency, not present in this function, linked to parameters including a “-“character in the name.
One example is “list-network.fence.network” which will use the parameter “fenceid” instead of “fence-id”.
This is due to the “OverloadDefinitions” extracted via get-Esxcli() which doesn’t contain any “-“ in this parameter name.
Line 71-72:The parameter VMhost is not present in esxcli, these cmdlets have been created for PowerCli and are expecting one or many VMhost object as a mandatory parameter.
Line 78-90:Parameters extracted from the OverloadDefinitions:
The type parameter of each parameter has been extracted from the “OverloadDefinitions”
Please note the “System.Nullable” used for all “long” and “boolean” parameters.
In many cases, when using a function via an EsxCLi object, all parameters defined in the “OverloadDefinitions” of a function must be defined. And if you don’t need a specific parameter it is necessary to assign a $null value to it.
BY using “System.Nullable” we ensure that the default value of this parameter will be $null if you don’t specify it when calling this cmdlet, and this $null value will be exactly in the right location in the esxcli command.
Without system.Nullable, if you call the cmdlet without specifying these parameters, a long will have a default value of “0” and a boolean a default value “False”.
Not present in this example, this is not needed for string[] which will have a default value of $Null if the parameter is not used when calling the function.
String is a little more subtle, more explanation will follow below.
Line 91-92:The parameter VMhost is unsurprisingly of type VMhost. The interesting part is that it is a mandatory parameter and accept pipeline. The benefit of this approach will be visible in some sample scripts later on.
Line 94: Start the process of this function
Line 96-106: Default to $Null for a string parameter
System.Nullable has not been used in the param section for the string type.
If it was working it would have been used, unfortunately this is not the case due to some PowerShell limitation. More details on the “joy” of working with string in Powershell here and an active bug.
In other words, all these “if” functions are just a dirty workaround around the issue above.
The result is that if you don’t specify a string parameter, the default value will be an empty string “”, and then converted to a real $null value if this parameter has not been specified when calling the cmdlet.
Line 107 AND 399-402: Try Catch unexpected error
If any unknown errors are identified during the execution of the script the error will be returned by the “Write-error” $_
This will be the case with the ping-network.diag if the DNS name of the “host2” cannot be resolved.
Line 108:$esxcli = Get-EsxCLI -VMHost $VMhost
Finally Get-Esxcli is used to obtain an esxcli object from the VMhost initially entered as a parameter.
Line 109-398: Build and switch
This is how this cmdlet become ESXi build aware.
First the $build of the host is identified and via the “Switch” the right treatment is applied.
There are actually 3 scenarios possible.
The $Build of the host is not one of the “Switch” option.
It can mean two things:
This build has not been tested yet. The list of build tested so far will be in a dedicated section.
OR this esxcli function doesn’t exist for this host.
In both cases the “default” value for the switch will be used, which is throwing the error
Write-error “This function is not available with this ESXi build:$Build OR has not been tested yet. Please refer to the blog for all builds tested and latest version of this script.”
This is matching the lines 395-397
This $Build is in the list and actually ALL parameters available for this cmdlet are matching parameters of the associated esxcli command for a host with this build.
In this case the esxcli command will be called with all parameters, and a psobject table will be returned with the VMhost object in the first column and the esxclioutput in the second.
This is matching the lines 387-393 for the build 2403361 for example.
Scenario 3, the tricky one.
This function is available in esxcli but actually one or more parameters of this cmdlet don’t exist in ESXCLI for this build. This will be the case for the ping-network.diag, and, so far, any build associated to ESXi version 5.1.0 and the parameter “netstack”
If you are planning to use one such parameter it means that it matters for you and if this parameter doesn’t exist for the host you are targeting, it is better to report an error instead of running the esxcli command while ignoring it.
Example with “799733”, Line 112-124.
Line 113: Check if you have called this cmdled with one or more parameters which don’t exist for this build, if it is the case the following error will be reported.
Write-error “At least one parameter is not compatible with this ESXi build:$Build ”
If this parameter was not used when called the cmdlet, the esxcli command will be run and you can notice that it will run with only the relevant parameters for this build.
799733
$esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$nexthop,$size,$ttl,$wait)
To put in perspective with 1331820
$esxcli.network.diag.ping($count,$debug2,$df,$host2,$interface,$interval,$ipv4,$ipv6,$netstack,$nexthop,$size,$ttl,$wait)
Last note regarding the esxcli network diag ping and fortunately only this function.
The parameters “interval” and “wait” have changed from “Long” to “string” type from 5.1 to 5.5
The script above has taken this into account, A “long” type will work in all case, so “long” is the type required for these two parameters.
Sample usage:
Finally the fun part.
All the scripts below will use extensively “-expandProperty”. From my own experience this is working well only with PowerShell 4.0.
Please be very careful and always test all cmdlets in a test environment first.
All scripts are provided as-is, use at your own risk.
Test if all hosts connected to a vCenter server can ping a NTP server.
The challenge here is that esxclioutput will provide you two CodeProperty “Summary” and “Trace”
$NTPSERVER = “10.0.0.10”
Get-VMhost | ping-network.diag -count 2 -host2 $NTPSERVER | select VMHOST –expand esxclioutput | select VMHOST -ExpandProperty Summary | ogv
Configure HP 3PAR storage claim rules for new hosts in a new cluster “Cluster01”
From the official documentation
esxcli storage nmp satp rule add -s “VMW_SATP_ALUA” -P “VMW_PSP_RR” –O “iops=1” -c “tpgs_on” -V “3PARdata” -M “VV” -e “HP 3PAR Custom Rule”
You will obtain the equivalent for all hosts in a cluster, without enabling SSH, by using:
Get-cluster –name “Cluster01” | get-vmhost | add-storage.nmp.satp.rule –satp “VMW_SATP_ALUA” –psp “VMW_PSP_RR” –pspoption “iops=1” –claimoption “tpgs_on” –vendor “3PARdata” –model “VV” –description “HP 3PAR Custom Rule”
And to check the result
Get-cluster –name “Cluster01” | get-vmhost | list-storage.nmp.satp.rule | select vmhost –expand esxclioutput | Where {$_.Vendor –eq “3PARdata”} | ogv
The inspiration for the next one is coming from a post from Ather Beg, who I had the chance to work with. How to remind yourself of Advanced Settings changes in ESXi.
Original command
esxcli system settings advanced list –d
Now let do this for all hosts connected to vCenter server.
Get-vmhost | list-system.settings.advanced –delta $True | select vmhost –expand esxclioutput | ogv
It is important to notice that the “delta” parameter is not available for all builds. If you were using get-esxcli directly maybe you could have experienced issues due to this.
If your host doesn’t support this parameter, errors will be returned and no esxcli command will be executed.
ESXi build tested so far:
Version | Build | Name | Release Date |
---|---|---|---|
6.0.0 | 2615704 | ESXi 6.0 Express Patch 1 | 09/04/2015 |
6.0.0 | 2494585 | ESXi 6.0 GA | 12/03/2015 |
5.5.0 | 2638301 | ESXi 5.5 Express Patch 7 | 07/04/2015 |
5.5.0 | 2456374 | ESXi 5.5 Express Patch 6 | 05/02/2015 |
5.5.0 | 2403361 | ESXi 5.5 Patch 4 | 27/01/2015 |
5.5.0 | 2302651 | ESXi 5.5 Express Patch 5 | 02/12/2014 |
5.5.0 | 2143827 | ESXi 5.5 Patch 3 | 15/10/2014 |
5.5.0 | 2068190 | ESXi 5.5 Update 2 | 09/09/2014 |
5.5.0 | 1892794 | ESXi 5.5 Patch 2 | 01/07/2014 |
5.5.0 | 1881737 | ESXi 5.5 Express Patch 4 | 11/06/2014 |
5.5.0 | 1746974 | ESXi 5.5 Express Patch 3 | 19/04/2014 |
5.5.0 | 1746018 | ESXi 5.5 Update 1a | 19/04/2014 |
5.5.0 | 1623387 | ESXi 5.5 Update 1 | 11/03/2014 |
5.5.0 | 1474528 | ESXi 5.5 Patch 1 | 22/12/2013 |
5.5.0 | 1331820 | ESXi 5.5 GA | 22/09/2013 |
5.1.0 | 2583090 | ESXi 5.1 Patch 7 | 26/03/2015 |
5.1.0 | 2323236 | ESXi 5.1 Update 3 | 04/12/2014 |
5.1.0 | 2191751 | ESXi 5.1 Patch 6 | 30/10/2014 |
5.1.0 | 2000251 | ESXi 5.1 Patch 5 | 31/07/2014 |
5.1.0 | 1900470 | ESXi 5.1 Express Patch 5 | 17/06/2014 |
5.1.0 | 1743533 | ESXi 5.1 Patch 4 | 29/04/2014 |
5.1.0 | 1612806 | ESXi 5.1 Express Patch 4 | 27/02/2014 |
5.1.0 | 1483097 | ESXi 5.1 Update 2 | 16/01/2014 |
5.1.0 | 1312873 | ESXi 5.1 Patch 3 | 17/10/2013 |
5.1.0 | 1157734 | ESXi 5.1 Patch 2 | 25/07/2013 |
5.1.0 | 1117900 | ESXi 5.1 Express Patch 3 | 23/05/2013 |
5.1.0 | 1065491 | ESXi 5.1 Update 1 | 25/04/2013 |
5.1.0 | 1021289 | ESXi 5.1 Express Patch 2 | 07/03/2013 |
5.1.0 | 914609 | ESXi 5.1 Patch 1 | 20/12/2012 |
5.1.0 | 838463 | ESXi 5.1.0a | 25/10/2012 |
5.1.0 | 799733 | ESXi 5.1.0 GA | 10/09/2012 |
5.0.0 | 2509828 | ESXi 5.0 Patch 11 | 26/02/2015 |
5.0.0 | 2312428 | ESXi 5.0 Patch 10 | 04/12/2014 |
5.0.0 | 2000308 | ESXi 5.0 Patch 9 | 28/08/2014 |
5.0.0 | 1918656 | ESXi 5.0 Express Patch 6 | 01/07/2014 |
5.0.0 | 1851670 | ESXi 5.0 Patch 8 | 29/05/2014 |
5.0.0 | 1489271 | ESXi 5.0 Patch 7 | 23/01/2014 |
5.0.0 | 1311175 | ESXi 5.0 Update 3 | 17/10/2013 |
5.0.0 | 1254542 | ESXi 5.0 Patch 6 | 29/08/2013 |
5.0.0 | 1117897 | ESXi 5.0 Express Patch 5 | 15/05/2013 |
5.0.0 | 1024429 | ESXi 5.0 Patch 5 | 28/03/2013 |
5.0.0 | 914586 | ESXi 5.0 Update 2 | 20/12/2012 |
5.0.0 | 821926 | ESXi 5.0 Patch 4 | 27/09/2012 |
5.0.0 | 768111 | ESXi 5.0 Patch 3 | 12/07/2012 |
5.0.0 | 721882 | ESXi 5.0 Express Patch 4 | 14/06/2012 |
5.0.0 | 702118 | ESXi 5.0 Express Patch 3 | 03/05/2012 |
5.0.0 | 623860 | ESXi 5.0 Update 1 | 15/03/2012 |
5.0.0 | 515841 | ESXi 5.0 Patch 2 | 15/12/2011 |
5.0.0 | 504890 | ESXi 5.0 Express Patch 1 | 03/11/2011 |
5.0.0 | 474610 | ESXi 5.0 Patch 1 | 13/09/2011 |
5.0.0 | 469512 | ESXi 5.0 GA | 24/08/2011 |
I am checking updates on this KB Correlating VMware products build numbers to update levels
The build 653509,ESXi 5.0 Express Patch 2, has not been tested. More details in the FAQ below.
FAQ:
Why not using alias in the powershell functions like in esxcli?
Unfortunately Powershell is not case sensitive. With esxcli network diag ping we can use “I” for interface and “i” for interval. This is not possible in PowerShell.
Will you make it available for ESXi 4?
No. The End of general support for ESXi 4.x was 21/05/2014
Why using the switch per ESXi Build and not per ESXi Version?
ESXi hosts within the same version but different build do not necessary have identical esxcli function.
“Esxcli system.security.certificatestore add” is only available for some builds of ESXi version 5.5
“Esxcli hardwareipmi sel clear” was not available in “ESXi 5.5 GA” and actually at the time of the publishing of this post you will not find this esxcli command in the official documentation, while it is available for all others 5.5 build.
This topic alone will deserve a dedicated post in the future. Done
Why the build 653509 “ESXi 5.0 Express Patch 2” is missing?
This is a little embarrassing question… I have never managed to install a host with this build even while using the “ESXi-5.0.0-20120404001-standard”. I just gave up on this one.
My ESXi host build is missing!
Please let me know, ask politely, and I will try to add them for the next update of the script.
I have some suggestions.
Good news. I am still in a learning process, so any good advice will be welcomed for the future updates of this script, which will then be available for everyone.
Known issues so far:
ESXi 6.0 GA – issue with device alias namespace.
The “esxcli device alias” namespace is present when connected to the host with “ssh”
However for this build only, in my test environment, it is not available with “Get-esxcli”
Consequently the two functions below are not available for this build:
Get-device.alias
lis-device.alias
The format of some values reported by get-esxcli is not the same as the format reported by esxcli
Example with List-hardware.pci.
This function will report values like for example “Device Class” in decimal format instead of the hexadecimal format returned by esxcli hardware pci list.
However if you use list-hardware.pci with the “class” parameter, esxcli expect this value to be in hexadecimal format.
This is actually due to the behaviour of get-esxcli.
If an esxcli function has a mandatory parameter (Required), this parameter is not mandatory in the cmdlet.
(I didn’t find a way to extract this information automatically so far.)
Bonus the hidden esxcli namespace:
If you are using “fusion-IO” maybe you will be interested to know that it has a dedicated namespace in “esxcli”.
FunctionName MethodHelp
Esxcli Fio attach Fusion-io utility to attach an ioDrive.
Esxcli Fio beacon Fusion-io utility to enable or disable the beacon for the card attached to a device node.
Esxcli fio bugreport Problem reporting utility for Fusion-io devices.
Esxcli fio detach Fusion-io utility to detach an ioDrive.
Esxcli fio format Fusion-io format utility. [B,K,M,G,T,P,%%] are units: Bytes, KBytes, MBytes, GBytes, TBytes, PBytes and percent.
Esxcli fio geterasecount Fusion-io utility to report statistics on block erase counts.
Esxcli fio pcicheck Fusion-io utility to checks for errors on the PCI bus tree, specifically for ioDrives. It is perfectly normal to see a few correctable errors when initially run. Subsequent runs should only reveal one or two errors for several hours of operation. MUST be used while the driver is loaded.
Esxcli Fio proctl Fusion-io proctl utility.
Esxcli fio readlebmap Fusion-io utility which reads the media event log out of the device.
Esxcli fio status General information utility for Fusion-io devices.
Esxcli fio updateiodrive Update ioDrive firmware. Note: MUST NOT be used while the ioDrive is attached.
Esxcli fio version Version of the Fusion-io utilities.
It seems to be associated to some “Drivers” which are part of the “ESXi 5.5 Update 2 Driver Rollup”
If there is a demand for it, I will consider the creation of dedicated cmdlet for these functions.
I think you might like the new version of PowerCLI we just released 😉
Check out Get-ESXCLI -v2
Ahh a link may help… https://t.co/wNxYkXU6bi
Pingback: Get-EsxCli on steroids - The Crazy Consultant