Expanding upon the basics demonstrated in Part I of this series, let’s now look at exporting multiple machines using a single PowerShell script. We’ll use the same director structure as outlined in Part I, but here we have a few additional challenges to overcome.
- Selecting the Virtual Machines to export.
- Ensuring that we only export one at a time to reduce the disk I/O and resulting disk fragmentation that will occur if simply try to export all of the machines at one time.
- You want to export the machines while they’re in a running state.
The following PowerShell script will do the job admirably, but let’s take a look at a few key sections that make this possible.
First the assumptions:
- HyperV Host is running Windows Server 2012 R2 as this will not work on Windows Server 2012.
Then the script: