VMware Cloud Community

plink vsphere 6.5

i am getting an error on this


$esxhosts = get-cluster -Name "cluster" | Get-VMHost


foreach ($vmhost in $esxhosts) {



$esxcli = Get-EsxCli -VMHost $vmhost



plink 'c:\scripts\plink.exe' $vmhost 'root' 'xxxxx' '/etc/init.d/vpxa restart'

plink 'c:\scripts\plink.exe' $vmhost 'root' 'xxxxx' '/etc/init.d/hostd restart'



start-sleep 20


-pw : The term '-pw' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the

name, or if a path was included, verify that the path is correct and try again.

At line:1 char:2

+  -"/etc/init.d/hostd restart; sleep 1; exit"

+  ~~~

    + CategoryInfo          : ObjectNotFound: (-pw:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException



any idea? this was working in vsphere 6.0. I am on powercli 6.3



Tags (1)
0 Kudos
1 Reply
Hot Shot
Hot Shot

Hi tdubb123,

I know this doesn't exactly solve your current issue but I myself moved away from invoking SSH commands using plink and started using PoSH-SSH which I found easier. So you could try something like this. You just need to install Posh-SSH by running # Find-Module Posh-SSH | Install-Module

Side note: vpxa can also be restarted natively via PowerCLI with the use of SSH


Written by Nicholas Mangravit 24.09.2017

PoSH-SSH Required

Tos Install PoSH-SSH Run > Find-Module Posh-SSH | Install Module


#Make sure Psh-SSH is loaded.

if ((Get-Module -Name Posh-SSH -ErrorAction SilentlyContinue) -eq $null ) { Import-Module "Posh-SSH" -Force:$true -WarningAction SilentlyContinue}

#VC and ESXi Connection Variables (EDIT THIS SECTION)

$vc = 'vc.vsphere.local'

$Cluster = 'My-Cluster-Name'

$vcCreds = Get-credential -Message "Enter Credentials to connect to vCenter Server" -UserName "administrator@vsphere.local"

$hostCreds = Get-credential -Message "Enter Credentials to connect to ESXi host" -UserName "root"

#Connect to vCenter

Connect-VIServer $vc -Credential $vcCreds

$vihosts = Get-Cluster $Cluster | Get-VMHost

#Connect to each ESXi Host & Restart Services

foreach ($vihost in $vihosts) {

$ssh = New-SSHSession -ComputerName $vihost -Credential $hostCreds -AcceptKey

Start-Sleep -Seconds 1

Invoke-SSHCommand $ssh -Command "/etc/init.d/vpxa restart"

Start-Sleep -Seconds 2

Invoke-SSHCommand $ssh -Command "/etc/init.d/hostd restart"

Write-Host -ForegroundColor Green "VPXA and hostd have been restarted on $vihost"

Write-Host -ForegroundColor Yellow "Sleeping for 20 Seconds"

Start-Sleep -Seconds 20

Remove-SSHSession $ssh


#Disconnect from VC and Clear Variables

Disconnect-VIServer $vc -Force

Remove-Variable * -Force -ErrorAction SilentlyContinue