4 Replies Latest reply on Dec 7, 2018 3:25 AM by LucD

    Restart Multiple VM Script - Error

    Bunty11 Enthusiast

      $servers = Read-Host "Enter FULL CSV Path"

      $Import = import-csv "$servers"

      Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false -Scope AllUsers

      Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false -Scope AllUsers


      $vCenters = 'xx.xx.xx.xx','xx.xx.x.xx'


      $user = 'xxxx'


      $keyFile = "\\xx\xxx\xxx\xxxxx\xxx\AES.key"


      $pswdFile = "\\xx\xxx\xx\xxxx\xxxx\Password.txt"


      $encryptedPswd = Get-Content -Path $pswdFile | ConvertTo-SecureString -Key (Get-Content -Path $keyFile)


      $cred = New-Object System.Management.Automation.PSCredential($user,$encryptedPswd)


      Connect-VIServer -Server $vCenters -Credential $cred


      foreach($i in $Import)


          $FindVM = Get-VM -Name $i.Servername -Server $vCenters

           Write-Host "Servers" $i.Servername

            if($FindVM.Name -eq $i.Servername)


          Write-Host "Present in $vCenters"

          Restart-VMGuest $i.ServerName -Verbose

          Write-Host "Restarting VM" $i.Servername




          Write-Host "Server :" $i.Servername "not in the Vcenters"



      Disconnect-VIServer -Server $vCenters -Force



      I GET THIS ERROR WITH MY ABOVE SCRIPT -"""Connect-VIServer : Could not establish secure channel for SSL/TLS with authority 'vCenter1'"""


      ALSO GET THIS ERROR - ""Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty.""