1 Reply Latest reply on Sep 23, 2017 6:45 PM by nicholas1982

    plink vsphere 6.5

    tdubb123 Master

      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

      +  -pw 4r8d3rzs! root@va-esxi5.wsgr.com "/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

       

      thanks

        • 1. Re: plink vsphere 6.5
          nicholas1982 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

          1 person found this helpful