VMware Cloud Community
Bunty11
Hot Shot
Hot Shot

Restart Multiple VM Script - Error

$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

    }

  else

    {

    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.""

Tags (1)
Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

For the TLS issue you might want to have a look at KB2137109 and KB2147469

For the Name parameter error, did you already try stopping/starting your PowerShell/PowerCLI session?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Bunty11
Hot Shot
Hot Shot

Yes, i have tried stating stopping VI Server session

Reply
0 Kudos
Bunty11
Hot Shot
Hot Shot

I can connect to vcenter using same connection method for a different script but not working in this script.

Reply
0 Kudos
LucD
Leadership
Leadership

Did you try with the FQDN for the vCenter(s)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos