This is one of these quick and dirty blog posts mostly as a note for myself. Hyper-V offers the capability to add an ISO image to a virtual CD/DVD drive and you can use Hyper-V Manager to do that, or you can also use PowerShell. Here is how you can eject or remove an ISO from a Hyper-V virtual machine (VM) using PowerShell.
Remove or eject ISO from Hyper-V VM using PowerShell
To remove or eject the ISO file from a Hyper-V VM virtual DVD drive, you can use the following PowerShell command:
Find the right DVD drive
Get-VMDvdDrive -VMName "Windows10"
Eject the ISO file from the Hyper-V VM
Get-VMDvdDrive -VMName "Windows10" | Set-VMDvdDrive -Path $null
You can also pipe these commands
Get-VM -VMName "Windows10" | Get-VMDvdDrive | Set-VMDvdDrive -Path $null
If you have multiple DVD drives and controllers on VM, you can also use the following command to be more specific on which ISO to eject.
Set-VMDvdDrive -VMName Windows10 -ControllerNumber 0 -ControllerLocation 1 -Path $null
You can also simply add an ISO to the Hyper-V virtual DVD drive:
Get-VMDvdDrive -VMName "Windows10" | Set-VMDvdDrive -Path "C:\ISO\myisofile.iso"
Be aware that it takes a moment until the ISO file is removed from the virtual DVD drive. You can find more information on the Set-VMDvdDrive cmdlet on Microsoft Docs.
If you want to build some automation around Hyper-V on Windows 10 or on Windows Server, PowerShell is the way to go. If you have any questions feel free to leave a comment.