Quick Tip–Adding Same ISO DVD Image To All Hyper-V Lab VMs

When building out a lab, you might need to attach the same ISO to multiple VMs.  In this case I was installing multiple Exchange 2016 severs, and wanted to easily add the same ISO file to each of the VMs.

This was on my Windows 10 laptop which makes quick work of the task since we can use PowerShell.

The VMs to target all have the same naming convention.  The VMs for the Exchange 2016 lab start with E16.  This allows us to use a wildcard in the Get-VM cmdlet to obtain the collection of VMs.  The ISO to mount is located in the F:ISOsExchange2016 directory.

Mounting ISO Image To All Lab VMs

The below is an example To mount the same ISO.  Then we check to make sure.

Get-VM E16* | Get-VMDVDDrive | Set-VMDvdDrive -Path "F:ISOsExchange2016ExchangeServer2016-x64-cu6.iso"
Get-VM E16* | Get-VMDVDDrive | Select-Object VMName, Path

Using PowerShell to Add Same ISO To Multiple VMs

Dismounting ISO Image To All Lab VMs

To dismount the ISO image when we are done, simply set the path to $Null.

Get-VM E16* | Get-VMDVDDrive | Set-VMDvdDrive –Path $Null

Then we check the values again using:

Get-VM E16* | Get-VMDVDDrive | Select-Object VMName, Path

Using PowerShell to Dismount ISO Image

Potential Truncated Paths Issue

Depending where you store ISOs, the displayed path may not be displayed by default.  If we use the same example as above:

Get-VM E16* | Get-VMDVDDrive | Select-Object VMName, Path

Truncated PowerShell Output -Expandproperty To the Rescue

Note that the second last ISO path is Truncated.  In order to see that we can use ExpandProperty.  However if we just do this, then we do not not get all of the previous columns due to the data type of the Path column....

Get-VM E16* | Get-VMDVDDrive | Select-Object –ExpandProperty Path

Truncated PowerShell Output -Expandproperty Removed Additional Columns

If we want to run this as a quick one-liner we can save off the expanded path property and then display along with the VMName.

This is just a quick example; there may be a more suitable method depending upon the exact requirements.

Get-VM E16* | ForEach { $Path = (Get-VMDVDDrive $_ | Select-Object -ExpandProperty Path);Write-Host $_.VMName $Path}

PowerShell One-Liner To Show VMName and Expanded Path Information



Rhoderick Milne [MSFT]

Leave a Reply

Your email address will not be published. Required fields are marked *