Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. $sourceVMName = "testvm"
  2. $numclones = 1
  3.  
  4. $i = 0
  5.  
  6. #Get each VM that matches wildcard pattern match *$sourceVMName* and sort them alphabeticaly decending *oldest last"
  7. ForEach ($vm in Get-VM | Where-Object { $_.Name -like "*$sourceVMName*" } | Sort -Property Name -Descending)
  8. {
  9. $i++
  10.  
  11. if ($i -gt $numclones) {
  12. Write-Host $vm.Name "would be deleted"
  13. }
  14. }
  15.  
  16. #$newVMName="clone-" + $sourceVMName + "-" + $i
  17. $newVMName="clone-" + $sourceVMName + "-" + (Get-Date).tostring("yyMMddHHmm")
  18. Write-host "would create a clone of $sourceVMName called $newVMName"
  19. #New-VM -Name $newVMName -VM $sourceVMName
  20.  
  21. #New-VM -Name $newVMName -VM $sourceVMName -VMHost $esxName
  22. #Get-VM -Name $newVMName | Remove-VM -DeletePermanently -Confirm:$false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement