A few people have blogged about using the plink.exe command line utility included with the Putty client distribution and I thoght I would add a couple of my own one-liners that I have used recently.
To those who don’t know, Plink is a command line SSH command line utility that can be ported to from Powershell scripts, amongst other scripting languages. The challenge with some commands that you have to execute on an ESX host is that the PowerCli doesn’t cover all of the possibilities (and I’m not sure it could) if you need to execute a native Linux command in the Service Console against several ESX hosts in a single one-line script.
To start, you need to obtain the Putty distribution, if you don’t have it already, and once installed, there will be a plink.exe file in the directory where Putty was installed. You need to move this file to somewhere in your %PATH% environment so Powershell can find it.
In order to run the one-liner against multiple hosts at one time, I create a comma-delimited (CSV) file containing only two columns – the host name and the root password. For my example I titled the colums “Server” and “Password” respectivly, but you could change that to whatever you like as long as you also change the syntax of the one-liner. I called my CSV file esxhosts.csv.
Here’s a one-liner that imports the esxhosts.csv file, located in C:temp, and runs plink to execute the native Linmux command to add a user (adduser):
import-csv c:tempesxhosts.csv | %{plink -l root root@($_.Server) -pw $_.Password useradd -c test user -g 100 -s /bin/false -p sazH3QxfGUVC6 testuser}
This one will add that user to allow them to have Read-Only rights to the host when managed by vCenter:
import-csv c:tempesxhosts.csv | %{plink -l root root@($_.Server) -pw $_.Password vmware-vim-cmd vimsvc/auth/entity_permission_add vim.Folder:ha-folder-root testuser false ReadOnly true}
*Remember – due to blog fomatting, these are split into multiple lines, but should be copied in_wpnonce=d95f97aff5