I have a virtual machine with the same name, but it belongs to a different vApp.
I need to perform snapshot recovery on both virtual machines at the same time.
Although I can use this command method, how can I solve the problem of error reporting?
The specified snapshot does not belong to the specified VM.
Get-View -ViewType VirtualMachine -Filter @{"Snapshot" = ""} -Property Name | % {Get-VM -id $_.MoRef | Get-Snapshot | Sort-Object -Property Created -Descending | Select-Object -First 1 | Set-VM 'test*' -Confirm:$false -RunAsync}
I'm not sure what you are trying to do.
With Get-View you select VMs that do not have a snapshot, and then you want to restore those VMs to a Snapshot.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My friend provided a way to solve the problem of batch snapshot recovery.
For ($i = 1; $i -le 2; $i++) {
$vAppName=("vApp-" + "{0:d2}" -f $i)
Write-Host "Revert a Snapshot for" $vAppName"..."
$VMs = Get-vApp $vAppName | Get-VM
ForEach( $vm in $VMs ) { Set-VM -VM $vm -Snapshot '20220105' -Confirm:$false }
# ForEach( $vm in $VMs ) { Start-VM $vm }
# Start-VApp $vAppName
}
Hope to be useful to others..... 🙂