Follow @chaderoth

Saturday, October 6, 2018

Use PowerCLI To Find Linux VMs With Connected ISO And Disconnect ISO Without Causing VM To Become Unresponsive

In my previous post I discussed what can happen if you attempt to disconnect an ISO from a Linux virtual machine before first ejecting or unmounting the media inside the guest operating system.

This can have dire consequences if you bring all of your Linux VMs to a screeching halt. It is easy enough to answer the prompt displayed in vCenter for a handful of VMs, but if you have a large Linux environment this could be cumbersome. The VM also returns to a running state as if it were paused, but this severs any connected sessions. Any outside operations running that use the affected VM as a resource will also be unsuccessful during this time.

What Happens When You Disconnect An ISO From A Linux VM While The Guest Operating System Still Has A Lock On The Media

If you have an operation you would like to perform and you do not inherently know how to perform said operation; what do you do? Well, I imagine like the majority of us you begin to scour the inter-webs for potential solutions.

In this case I wanted to find a way to easily and systematically find all of the virtual machines in my environment that had an ISO mounted to the virtual machine and then disconnect the ISO without any manual intervention on my part, other than perhaps running the script.

My goto for this task of course was PowerCLI. I have found that the more I play with and get to know PowerCLI the more excited I become about the possibilities it offers.

If you do a quick internet search for tasks like, "Use PowerCLI to get all VMs with a mounted ISO and disconnect ISO" you will find loads of blog posts on how to perform this task and some with different code styles and syntax, but all fairly basic as PowerCLI makes this a pretty simple operation.

The problem I discovered with this...well, actually I discovered a few problems.