VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

Shutdown-VMGuest -VM $vm -RunAsync is not working

Hi,

I am getting the below error, while shutting down multiple VMs from a particular folder. I would like to shutdown multiple VMs in parallel

Stop-VMGuest : A parameter cannot be found that matches parameter name 'RunAsync'.
At D:\Date\Shutdown_VMs_Particular_Folder\Shutdown_VMs_Particular_Folder.ps1:6 char:54
+ Shutdown-VMGuest -VM $vm -Confirm:$false -RunAsync
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Stop-VMGuest], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.StopVmGuest

 

Script

$VMList = Get-Folder MyTest | Get-VM
$report = @()
foreach($vm in $VMList){
if($vm.PowerState -eq 'PoweredOn'){
if($vm.Guest.State -eq "Running"){
Shutdown-VMGuest -VM $vm -Confirm:$false -RunAsync
} else {
Stop-VM -VM $vm -confirm:$false -RunAsync
}
Write-Host "Shutting Down $vm at $(get-date)"
Start-Sleep 10
$report += New-Object PSObject -Property @{
'VM_Name' = $vm
'Power_Off_Time' = Get-Date -Format 'MM/dd/yyyy HH:mm:ss'
}
}
}
$report | ft -auto

0 Kudos
3 Replies
LucD
Leadership
Leadership

There is, as the error message states, no RunAsync switch for the Stop-VMGuest cmdlet.
The reason is that the underlying ShutdownGuest method also has no _Task suffix.

As an alternative, you could run each Stop-VMGuest via a Start-Job cmdlet.
Then the cmdlet runs in the background, and you can start multiple in parallel


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

I would like to understand when I can use ShutdownVM-Guest and Stop-VMGuest  ? Does Stop-VMGuest powers off the VMs abruptly ? 

0 Kudos
LucD
Leadership
Leadership

The Shutdown-VMGuest is an alias for Stop-VMGuest.
Both do exactly the same


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

0 Kudos