0

I am working on a PowerShell script that (among other things) gets the currently logged in user to a list of VM's, using WMI to get the owner of any explorer.exe processes.

$User = Get-WmiObject -Class win32_process -ComputerName $strVMName -Credential $cred | `
Where-Object{ $_.Name -eq "explorer.exe" } | `
ForEach-Object{ ($_.GetOwner()).Domain + "\" + ($_.GetOwner()).User; }

This code works great, but only when the credentials used are an admin on the VM being queried. I have given a non-admin user full rights on CIMV2 in WMI Control, but the GetOwner method doesn't return anything ($user is returned as just "\") unless I add the user to the admin group as well. Since this script is intended to be run by normal users, I would rather not give them admin rights.

Can someone point me to what the minimum rights needed to use these methods? Or even a different method of getting the currently logged in user that will work for non-admins?

0 Answers0