Q. How can I bulk import every exported virtual machine (VM) in a folder?

John Savill

May 29, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. Using the CodePlex Hyper-V module referenced in FAQ "Q. Is there a PowerShell set of cmdlets for Hyper-V outside of using VMM?" you can use the Import-VM cmdlet. Combine this with logic to list every folder in a path to create a command to import every VM in a folder (assuming each VM is in its own child folder). Notice that you use the -Wait switch for the Import-VM to import only one VM at a time.

Get-ChildItem e:virtuals | Where-Object { $_.Attributes -band [System.IO.FileAttributes]::Directory } | ForEach-Object {Import-VM -path $_.FullName -ReuseIDs -Wait}

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like