Unmount floppy drives in PowerCLI

Unmount floppy drives in PowerCLI

At work I had to remove a datastore in our VMware enviroment, but when I took a closer look, there were a lot of VMs which had connections to this datastore. Looking at the first few, it was clear that they for some reason had a floppy disk image configured from that datastore. Using the vSphere client it would be time consuming to manually find the VMs and reconfigure them, so therefore I used PowerCLI instead.

To identify all VMs, which have connections to a specific datastore, and also have a Floppy disk image set, I used the following one-liner.

Get-VM -Datastore [DATASTORE NAME] | Get-FloppyDrive | ? {$_.FloppyImagePath -ne $null} | ft Parent, Floppyimagepath

powercli-floppylist

By appending the Set-FloppyDrive -NoMedia in the pipeline, PowerCLI will remove the image path for the VMs.

Get-VM -Datastore [DATASTORE NAME] | Get-FloppyDrive | ? {$_.FloppyImagePath -ne $null} | Set-FloppyDrive -NoMedia

powercli-floppysetnomedia

 

Another trivial job made easy using PowerShell/PowerCLI… 🙂