Eject DVD iso from Hyper-V 2012 using PowerShell

Very short article this one. Ever tried googling/binging for how to eject the dvd-drive in Hyper-V 2012 using PowerShell? It is actually very easy and logical, and also documented in the examples.

The following Get-Help cmdlet shows you how to do this.

# Get-Help Set-VMDvdDrive -examples

Basically do the following to eject ALL your dvd-drives (first line), or use the second line to eject all dvd drives that have mounted an ISO from the E:\Install directory. You can of course also use the third line to eject from a single VM.

# Get-VM | Get-VMDvdDrive | Set-VMDvdDrive -path $null
# Get-VM | Get-VMDvdDrive | where{if($_.Path) {$_.Path.ToLower().StartsWith("e:\install\")}} | Set-VMDvdDrive -path $null
# Get-VM dc1.marius.local | Get-VMDvdDrive | Set-VMDvdDrive -path $null

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s