≡ Menu

PowerShell: Find out who else logged on to a VM console using virtual center

Often we see below message when we try connecting to a console of virtual machine using Virtual Center MMC.

“Number of Active Connections has changed. There are now X active connections to this console.”

All it indicates is someone else is also sharing the console. Most VMware admins found it frustrating because, it is diverting the attention and even if you close it, it will pop-up again. Looks like there is no option to disable this message. Read http://communities.vmware.com/thread/81825 if you need more details about the problem.

Since there is no way available around to disable that, can we have some workaround? One thing we can do is ask the persons who are currently connected to disconnect their sessions. But the question here is “how we know who all are connected”? There is no straight forward option in GUI to find out the users, but you can use VMware powershellCLI to get this information.

 

function Get-VMConsoleConnectedUser {            
param (            
$VmName,            
$VCName            
)            

Connetct-VIServer -Server $VCName            
$VMEntity = Get-VM $VMName            
Get-VIEvent -Start (Get-Date).addhours(-5) -Enity $VMEntity | ? `
{$_.FullFormattedMessage -like "Remote Console*"} | select Username,FullFormattedMessage, createdtime            

}

A few things you should keep in mind before using the above function:

  • You should execute this from a powershell console where PowerCLI add-in is available
  • This function is not having any error handling capabilities
  • By default script looks for remote console logins in last 5 hours. Change the (get-date).addhours(-5) section if you would to change it.
  • Always test it before you run in production

This is my first attempt to manage VMware Virtual center with powershell.

Hope this article helps.