Reply to Message

View discussion in a popup

Replying to:
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

Reply
0 Kudos