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-VMLoggedOnUserfrom 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
SYSTEM, etc. or, for example
MSSQL*service accounts will be excluded from the output.
Which VM are supported?
Get-VMLoggedOnUsersupports 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 . 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-VMLoggedOnUserwill silently skip unsupported VM with no error message until you use
-Verboseswitch 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
-ExcludeLocalswitch will return domain accounts only.
Get-VM | Get-VMLoggedOnUser –ExcludeLocal
- The second parameter
-Usernameis 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
-imatchoperator! The regex itself is out of scope of this article, please use
Get-Helpfor 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