Run ESXi Commands Via PowerShell And SSH

Some ESXi CLI commands have no alternative in PowerCLI and you have to run the commands on ESXi via SSH or locally. But there is another easier way to run batch commands and get result.

You can use PLINK on this regard. Plink is one of Putty components, so you need to have plink.exe on your local drive or any location which to be accessed.

Change the below script parameters and run your commands as you like:

$User = <User>
$Pswd = <Host Password>
$hostName = <Host>
$plink = <PLink Path> "\plink.exe"
$plinkoptions = " -v -pw $Pswd"
$cmd1 = ' esxcli vm process list'
$remoteCommand = '"' + $cmd1 + '"'
$command = "Echo Yes| "+$plink + " " + $plinkoptions + " " + $User + "@" + $hostName + " " + $remoteCommand
$result = Invoke-Expression -command $command
$result

[quotes_and_tips]

Davoud Teimouri

Professional blogger, vExpert 2015/2016/2017/2018/2019/2020/2021/2022/2023, vExpert NSX, vExpert PRO, vExpert Security, vExpert EUC, VCA, MCITP. This blog is started with simple posts and now, it has large following readers.

1 Response

  1. 26/01/2024

    […] Run ESXi Commands Via PowerShell And SSH […]

Leave a Reply

Your email address will not be published. Required fields are marked *