Tag: Drive

Eject ISO from Hyper-V VM using PowerShell

Eject ISO from Hyper-V VM using PowerShell

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.

This works with Hyper-V on Windows Server and on Windows 10.

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.

Conclusion

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.



Add ISO DVD Drive to a Hyper-V VM using PowerShell

Add ISO DVD Drive to a Hyper-V VM using PowerShell

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 add an ISO to a Hyper-V virtual machine (VM) using PowerShell. There are two ways of doing it if you already have a virtual DVD drive attached to the VM or if you need to add a virtual DVD drive.

This works with Hyper-V on Windows Server and on Windows 10.

Attach ISO to an existing DVD Drive on a Hyper-V VM using PowerShell

To attach an ISO file to an existing virtual DVD drive on a Hyper-V virtual machine (VM) using PowerShell, you can use the following command:

Set-VMDvdDrive -VMName Windows10 -Path "C:\Users\thoma\Downloads\ubuntu-18.04.4-live-server-amd64.iso"

Add ISO file and DVD Drive to a Hyper-V VM using PowerShell

If your Hyper-V virtual machine doesn’t have a virtual DVD drive attached to it, you can add a virtual DVD drive including the ISO file with the following PowerShell command:

Add-VMDvdDrive -VMName "Windows10" -Path "C:\Users\thoma\Downloads\ubuntu-18.04.4-live-server-amd64.iso"

If you run this command on a virtual machine, which already has a virtual DVD drive attached, you will simply add a second virtual DVD drive to this machine. You can find more information on the Add-VMDvdDrive cmdlet on Microsoft Docs.

Conclusion

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.