Hello team
I'm trying to create a script to take snapshot for bunch of VMs at one shoot and each snapshot should has a unique snap name (prefers Snapshot name format : 'VM_Name - time'
Script:
$importVMfile = 'VM1', 'VM2', 'VM3', 'VM4'
$TimeforSnap= get-date -format "yyyyMMdd HH:mm:ss"
Get-VM | Where-Object {$_.name -in $importVMfile} | New-Snapshot -name "$_.Name - $TimeforSnap" -Confirm:$false -RunAsync
script output:
VM | Snap-Name |
VM1 | $_.Name - 20220910 20:55:42 |
VM2 | $_.Name - 20220910 20:55:42 |
VM3 | $_.Name - 20220910 20:55:42 |
VM4 | $_.Name - 20220910 20:55:42 |
Expected output:
VM | Snap-Name |
VM1 | VM1 - 20220910 20:55:42 |
VM2 | VM2- 20220910 20:55:42 |
VM3 | VM3 - 20220910 20:55:42 |
VM4 | VM4 - 20220910 20:55:42 |
so how to get the expected output to allow its own name appear in the snap name