Search code examples
vmwarepowercli

VMWare powercli to check who's using what VM


Ok, here's the problem: We have a lot of virtual machines on our server that are up and running pretty much 24/7. If we need to shut down a VM for any reason, what we normally do is open it up in either workstation or vsphere in a console and stare at it to see if any windows open/close or if the mouse is moving. Looking for a command/script to let us know what user is accessing what VM from the server.

I've done some research and played around with Vshpere CLI and VMware powerCLI, but haven't been able to find this information. Would save us all alot of time to know who has what VM open on their console.


Solution

  • So I figured out the there are mks events triggered when a user opens the console. (mks=mouse/keyboard/screen) So by using the get-VIEvent command in powercli, filtering out what I wanted, ended up with what I was looking for. Here's the segment of code I was looking for in case anyone else is looking for an answer

    Get-VIEvent | Where {$.TicketType -eq "mks"} | Select UserName, @{N='VM';E={$.Vm.Name}}, CreatedTime