Eject ISOs from Virtual Machines in a Cluster

Easily eject ISOs from all virtual machines in a cluster.

John Savill

May 12, 2014

1 Min Read
ejector seat

Q: How can I eject the ISO files from all DVD drives attached to virtual machines in a cluster?

A: The following PowerShell code will eject the ISO files from all virtual machines in a cluster.

$VMsinCluster = Get-ClusterResource | Where-Object {$_.ResourceType -eq "Virtual Machine"} | Get-VMforeach ($VM in $VMsinCluster){    $VMDrive = Get-VMDvdDrive -VM $VM    if ($VMDrive.DvdMediaType -eq "ISO")     {        Write-Host "Removing ISO from" $VMDrive.VMName        Get-VMDvdDrive -VM $VM | Set-VMDvdDrive -Path $null    }}

Just run this PowerShell code in the cluster, and ISO files will be ejected from all virtual machines in the cluster.

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like