Hugo Peeters has a great function for using WMI to get Logged on Users: http://www.peetersonline.nl/index.php/powershell/oneliner-get-logged-on-users-with-powershell/
This can be easily used in PowerCLI. This can be very useful when you need to do some VM maintenance in a VDI environment and need to find out who is currently logged on and know which VMs are not in use and can be worked on.
$VMs = Get-Cluster "LON\_PROD1" | Get-VM | Where { $\_.PowerState -eq "PoweredOn" } ForEach ($VM in $VMs) { Write-Host "Logged On Users for: " $VM.Guest.HostName Get-WmiObject Win32\_LoggedOnUser -ComputerName $VM.Guest.HostName | Select Antecedent -Unique | %{"{0}\\{1}" -f $\_.Antecedent.ToString().Split(’"‘)\[1\], $\_.Antecedent.ToString().Split(’"‘)\[3\]} }