Created
January 15, 2023 11:04
-
-
Save PatrickTerlisten/d467eb25d2bf81a297989a562d583b88 to your computer and use it in GitHub Desktop.
Save a VM <> host mapping and redistribute VMs according to the stored mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Discover all VMs in a specific vSphere Cluster | |
$AllVMs = Get-Cluster PROD | Get-VM | ? { $_.Name -notlike 'vCLS*' } | |
### Create empty hash table | |
$hashtable = @{} | |
### Fill hash table with a mapping VM <> host | |
foreach ($i in $AllVMs) { | |
$hashtable.add($i.name, $i.vmhost) | |
} | |
### Move VM to the original host | |
foreach ($i in $hashtable.GetEnumerator()) { | |
move-vm -VM $($i.Name) -Destination $($i.Value) -RunAsync | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment