How to list all the PowerCLI ESXCLI commands

Last week there was a question in the VMware VMTN Communities VMware vSphere PowerCLI forum from Papires who asked how you can convert the ESXCLI command ‘esxcli storage vmfs snapshot mount -l “DATASTORE”‘ into a PowerCLI command. I had not done very much with ESXCLI in PowerCLI, but I knew that it was something like ‘$esxcli.storage.vmfs.snapshot.mount’. However I was struggling with the ‘-l “DATASTORE”‘ part.

There is not much documentation available about the ESXCLI commands in PowerCLI. And also a search in Google did not help me very much. Finally I found the right answer using the PowerShell Get-Member cmdlet.

Using the Get-EsxCli cmdlet

If you want to use an ESXCLI command in PowerCLI you first have to create a EsxCliImpl object using the Get-EsxCli cmdlet. An example is shown in listing 2.

The Get-Member cmdlet output

The PowerCLI command ‘$esxcli.storage.vmfs.snapshot | Get-Member’ gave me the following output:

I now knew that the mount CodeMethod needs three parameters: nopersist, volumelabel and volumeuuid. Because Papires wanted to specify a volumelabel and probably wanted a persistent mount, I came to the following answer to his question.

The Get-EsxCliCommand function

Because I could find the right answer using the Get-Member cmdlet, I decided to write a PowerCLI script that can give me all the possible PowerCLI ESXCLI commands.

The Get-EsxCliCommand PowerCLI function lists all the possible PowerCLI ESXCLI commands. It does this by using the PowerShell Get-Member cmdlet to list each CodeProperty property and CodeMethod method of the EsxCliImpl or EsxCliElementImpl object that is given as input. Then the function calls itself for each CodeProperty. A function like Get-EsxCliCommand that calls itself is called a recursive function.

Like this:

Related

About Robert van den NieuwendijkRobert van den Nieuwendijk is a freelance senior systems engineer with over 30 years of experience in the IT industry. He focusses on VMware vCloud Suite and Microsoft Windows Server. He tries to automate as much of his work as possible using Microsoft PowerShell.
Robert is the author of the books “Learning PowerCLI” and “Learning PowerCLI – Second Edition.” Robert is a frequent contributor and moderator at the VMware VMTN Communities. He has a bachelor degree in software engineering and holds the following IT certifications and accreditations:
VSP 2016, VTSP 2016, VCP4-DCV, VCP5-DCV, VCP6-DCV, VCP6-CMA, VCA-Cloud, VCA-WM, VCA-NV, VMSP, VMTSP, ZCS, ZCP, ZCP-Cloud, MCSE, MCSA, MCP, MCP+I, PRINCE2 Foundation and ITIL Foundation.
In 2012, 2013, 2014, 2015, 2016 and 2017 Robert received the VMware vExpert award for his contribution to the community of VMware users over the past year. In 2017 Robert also received the VMware vExpert Cloud award.
PernixData made him in 2015 a member of the PernixPro.

12 Responses to How to list all the PowerCLI ESXCLI commands

Hi Robert – Thanks very much for your quality scripting tutorials, they have been very useful. I have a question on the listing #2 above – “DATASTORE” – how/where do you go to get this volumelabel? – I get this error when I put in what I presume to be correct:

Robert, I issued this command:
$esxcli.storage.vmfs.snapshot.list()
and nothing returns – total rookie question I’m sure, but – I’m connected to the vCenter server, and was able to set the $esxcli variable, but could it be I must be connected to the ESXi host itself to get results from this $esxcli.storage.vmfs.snapshot.list()? or, is it possible that I just don’t have any ‘unresolved VMFS snapshot’ on this Cluster?

Ryan, you don’t have to connect to the ESXi host directly. You can test that with another command. E.g. $esxcli.network.ip.interface.ipv4.get(). That command should give some output. It is possible that you don’t have any ‘unresolved VMFS snapshots’ in this cluster.

if you want the Get-EsxCliCommand function to be available when you use PowerCLI then there are several options. You can add the function to your PowerShell profile. You can edit your profile with typing “Notepad $profile” in PowerShell. You can also create a PowerShell module and put all the functions that you want to include in your PowerCLI sessions in this module. You can import the module with: “Import-Module modulename”. You can also add the Import-Module command to your profile.