February 9, 2014

Identifing, Unmounting CDs, and Rescanning the HBAs with VMware PowerCLI

Identifing, Unmounting CDs, and Rescanning the HBAs
with VMware PowerCLI

VMotion Failing?

These VMware PowerCLI commands, came in handy a month or so ago. I'd thought I'd share. Credit is given in the links below.

What do you do when, you see a mounted ISO not being used? Left abandoned and discarded? Does it drive you absolutely mad? Do you go all stabby Joe? Does the OCD kick in and you need to find and unmount the entire world. Then the below may help.

In all seriousness though, a mounted ISO will cause a VMotion to fail.

Detect which VM’s have CDs mounted

Get-VM | Where-Object {$_ | Get-CDDrive | Where-Object { $_.ConnectionState.Connected -eq "true" } } | Select-Object Name

Detect which VM's have CDs mounted and unmount the ones found

Get-VM | Where-Object {$_ | Get-CDDrive | Where-Object { $_.ConnectionState.Connected -eq "true" } } | Get-CDDrive | Set-CDDrive -Connected $false -Confirm:$false

Rescan HBA’s in a cluster

Get-Cluster 'Cluster 1' | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs

Resources

  1. https://www.simple-talk.com/sysadmin/virtualization/10-steps-to-kick-start-your-vmware-automation-with-powercli/