Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $sourceVMName = "testvm"
- $numclones = 1
- $i = 0
- #Get each VM that matches wildcard pattern match *$sourceVMName* and sort them alphabeticaly decending *oldest last"
- ForEach ($vm in Get-VM | Where-Object { $_.Name -like "*$sourceVMName*" } | Sort -Property Name -Descending)
- {
- $i++
- if ($i -gt $numclones) {
- Write-Host $vm.Name "would be deleted"
- }
- }
- #$newVMName="clone-" + $sourceVMName + "-" + $i
- $newVMName="clone-" + $sourceVMName + "-" + (Get-Date).tostring("yyMMddHHmm")
- Write-host "would create a clone of $sourceVMName called $newVMName"
- #New-VM -Name $newVMName -VM $sourceVMName
- #New-VM -Name $newVMName -VM $sourceVMName -VMHost $esxName
- #Get-VM -Name $newVMName | Remove-VM -DeletePermanently -Confirm:$false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement