Using PowerCLI to remotely execute esxcli commands
First, make sure you’re using a version of PowerCLI that supports the get-esxcli cmdlet. In this case, I used a fresh install of PowerCLI 5.5.
First, get-esxcli needs to be run against a single host individually, you can loop through you’re hosts later, but again, one at a time. So I did:
$getcli = Get-EsxCli -VMhost vmhost.domain.local
In my case, I wanted to remove a “greyed out” NFS mount, and in esxcli, I would run:
esxcli storage nfs remove -v nfsvolume
Well, the host I want to do this on does not allow SSH access to run it locally, so I’ll run it though powershell using:
$getcli.storage.nfs.remove("nfsvolume")
To re-add it back in esxcli, I would do:
esxcli storage nfs add -H nfshost.domain.local -s /path/to/export -v nfsexport
To re-add it back using PowerCLI to execute esxcli, I did:
$getcli.storage.nfs.add("nfshost.domain.local",$false,"/path/to/export","nfsexport")
What an awesome way to utilize PowerCLI!