Who is logged on to my VM?


Do you know who is logged on to your Virtual Machines? How many of them are domain and how many are local accounts? Are you sure what you know where in your virtual infrastructure particular user is logged on right now? And finally the last question, do you want to know? If the answer is Yes – this article especially for you.


  • The function ​Get-VMLoggedOnUser from my PowerCLi Vi-Module module will respond all of these questions. Just pass a single or multiple VM to the function and you are done.

  • Single VM

Get-VM vm1 | Get-VMLoggedOnUser


  • Multiple VM
Get-VM 'vm[0-9]' | Get-VMLoggedOnUser | Format-Table –AutoSize
Get-Folder $FolderName -Type VM | Get-VM | Get-VMLoggedOnUser
Get-Datacenter $DatacenterName | Get-VM | Get-VMLoggedOnUser
Get-Cluster $ClusterName | Get-VM | Get-VMLoggedOnUser
  • For long time operations the progress bar is provided.


  • The system accounts like NETWORK SERVICE, SYSTEM, etc. or, for example MSSQL* service accounts will be excluded from the output.

Which VM are supported?

  • The Get-VMLoggedOnUser supports powered on Windows VM based NT6 and above kernel only. By reason of the function interacts with VM guest are all these requirements. Windows XP/2003 Server are not supported Emoj. More than fifteen years have passed. Do you still have them?
  • Does it mean you have to filter these VM out before you pass them to the function? Definitely no. The Get-VMLoggedOnUser will silently skip unsupported VM with no error message until you use -Verbose parameter. The -Verbose switch will notify you about all skipped VM and the reason why it was skipped. There are three major reasons: VM power state, VM guest state and unsupported VM guest.

Get-VM | Get-VMLoggedOnUser -Verbose



  • The function has in all two optional parameters. The -ExcludeLocal switch will return domain accounts only.
Get-VM | Get-VMLoggedOnUser –ExcludeLocal


  • The second parameter -Username is intended to user search. It tries to find user accounts which names match the search criteria.
Get-VM | Get-VMLoggedOnUser -Username adm
Get-VM | Get-VMLoggedOnUser -Username '^adm'
Get-VM | Get-VMLoggedOnUser -Username 'adm$'


  • The user account running current PowerShell session is excluded from the output, so if you want to search you own account, run the PowerShell console with different administrative user.
runas /u:$Domain\$User powershell.exe


  • The search is case insensitive regex and uses -imatch operator! The regex itself is out of scope of this article, please use Get-Help for more advanced regex examples.
Get-Help Get-VMLoggedOnUser -Examples
  • Note, the parameters relate to different parameter sets and cannot be used together.


  • For more details about the function, please take a look at the content based help and examples.
Get-Help Get-VMLoggedOnUser -Full
Get-Help Get-VMLoggedOnUser -Examples
Get-Help Get-VMLoggedOnUser -Parameter ExcludeLocal

You might also like

Test-VMHotfix/Test-VMPing – Check VMware VM for installed Hotfixes
Copy VMware VM Notes to Computer/AD Computer Description
Expand-VMGuestPartition – Extend VM Guest Partition w/PowerCLi
Set-PowerCLiTitle – Connect-VIServer deep dive

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s