Bulk import VMs while changing the virtual switch name
Bulk import VMs while changing the virtual switch using PowerShell
November 8, 2015
Q. How can I bulk import VMs into a Hyper-V server while changing the network switch it is connected to?
A. I recently had to move a large number of VMs to a new cluster. The new cluster used a new name for the virtual switch which would block a normal import of the VM (remember that in 2012 you do not have to first export VMs to be able to import them). Fortunately it is simple to find a list of compatibility problems (which would be the bad switch name) and then correct. Below is the script.
$XMLFiles = Get-ChildItem C:ClusterStorageVMs*.XML -Recurseforeach ($File in $XMLFiles){ $File.FullName $Report = Compare-VM -Path $File.FullName $Report.Incompatibilities[0].Source | Connect-VMNetworkAdapter -SwitchName 'Datacenter Switch No Team' Import-VM -CompatibilityReport $Report}
Note that the script only works if the VM has a single NIC that needs to be updated and there are no other problems. If there are other issues the import will fail.
About the Author
You May Also Like