VMware PowerCli: Eject CD/DVD Media from VMs

Hi,

when you have to eject or unmount DVD iso from your VMs, may be the iso files resists on datastore you want to remove, these one liner should help you.

This ejects all DVDs or CDs from your VMs

PS D:\> get-vm|Get-CDDrive|Set-CDDrive -NoMedia -Confirm:$false

This ejects all DVDs or CDs from your VMs where the iso files are at datastore0

PS D:\> get-vm|Get-CDDrive|?{$_.IsoPath -match "^\[datastore0\] .*"}|Set-CDDrive -NoMedia -Confirm:$false

Or for a specific VM

PS D:\> get-vm "yourVM"|Get-CDDrive|Set-CDDrive -NoMedia -Confirm:$false

Michael

Leave a Reply