People,
This is the error I got when I try to connect to the console. MKS Internal Error due to "RemoteDisplay.maxConnections with a value of 1" is in effect.
Hello, AlbertWT-
Well, it looks like there is another way. You could get the number of current MKS (Mouse Keyboard Screen) connections for the given VM, and use that value for your Select statement. That should correspond with the users with current MKS connections to that VM.
$strVMName = "myVM"
## get VM; will use an ExtensionData value from this later
$vm = Get-VM -Name $strVMName
## get the events that are for console connects, sort, and then select the first X items, based on the number of current MKS connections
Get-VIEvent $vm | ? {$_.FullFormattedMessage -like "Remote console Connected*"} | Sort CreatedTime -Descending | Select UserName, CreatedTime -First $vm.ExtensionData.Summary.Runtime.NumMksConnections | ft -AutoSize
## same, but check the event type instead of a string compare on the FullFormattedMessage (just to not rely on string compares)
Get-VIEvent $vm | ? {$_ -is [VMware.Vim.VmRemoteConsoleConnectedEvent]} | Sort CreatedTime -Descending | Select UserName, CreatedTime -First $vm.ExtensionData.Summary.Runtime.NumMksConnections | ft -AutoSize
Both should work, but the second version removes the dependency on the string comparision. So, if the FullFormattedMessage changes in future vSphere implementations, things should still work (though, this would still be vulnerable to breaking if VMware changes the type name for the event). Somewhat of a preference thing.
How does that do for you?
Note: by sorting on CreatedTime, this process assumes that the current console connections were made sequentially. That is, if someone has been connected to the VM's console since yesterday, and you connect / disconnect / re-connect, _you_ will have the two most recent Connect events.
This may be what you are looking for.
get-vm -Name MyVM | Get-VIEvent | where { $_.fullFormattedMessage -like "Remote console Connected*" } | select userName
Many thanks for your response Hosted,
I have modified the script to be like the following for simplicity purpose:
get-vm -Name "DB01-VM" | Get-VIEvent | where { $_.fullFormattedMessage -like "Remote console Connected*" } | Sort CreatedTime -Descending | select userName, CreatedTime -First 1 | ft -AutoSize
However the test scenario is failed since it can only returns the last person who tried to access into the VM and that was me (Myself) so it is not always correct in determining who is currently viewing the VM right now.
You should drop the -First 1 parameter from the Select-Object to see all console connections over time.
The way you do it, you only see the most recent connection.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Yes I was trying to get the correct way of identifying who is currently using the Vsphere console session into a particular VM but it seems that it is not possible.
So I must conclude that the script above at least the only way to know who is currently connecting by manually parsing the result by eyes.
Any other input and suggestion would be greatly appreciated.
Thanks,
AWT
Hello, AlbertWT-
Well, it looks like there is another way. You could get the number of current MKS (Mouse Keyboard Screen) connections for the given VM, and use that value for your Select statement. That should correspond with the users with current MKS connections to that VM.
$strVMName = "myVM"
## get VM; will use an ExtensionData value from this later
$vm = Get-VM -Name $strVMName
## get the events that are for console connects, sort, and then select the first X items, based on the number of current MKS connections
Get-VIEvent $vm | ? {$_.FullFormattedMessage -like "Remote console Connected*"} | Sort CreatedTime -Descending | Select UserName, CreatedTime -First $vm.ExtensionData.Summary.Runtime.NumMksConnections | ft -AutoSize
## same, but check the event type instead of a string compare on the FullFormattedMessage (just to not rely on string compares)
Get-VIEvent $vm | ? {$_ -is [VMware.Vim.VmRemoteConsoleConnectedEvent]} | Sort CreatedTime -Descending | Select UserName, CreatedTime -First $vm.ExtensionData.Summary.Runtime.NumMksConnections | ft -AutoSize
Both should work, but the second version removes the dependency on the string comparision. So, if the FullFormattedMessage changes in future vSphere implementations, things should still work (though, this would still be vulnerable to breaking if VMware changes the type name for the event). Somewhat of a preference thing.
How does that do for you?
Note: by sorting on CreatedTime, this process assumes that the current console connections were made sequentially. That is, if someone has been connected to the VM's console since yesterday, and you connect / disconnect / re-connect, _you_ will have the two most recent Connect events.
Hi Matt,
Thanks for your reply, so at least with your script I can minimize the search scope of the people who is using the console.