OK, so I had some extra time on my hands today, and as an exercise for myself
decided to see if I could come up with a PowerShell one-liner that would list
out process name, and owner. Found a few things that I was surprised about and
wanted to pass on in case it saves someone else some time. Eventually I came
up with this:
Get-WmiObject Win32_Process| Select Name,
@{L="UserName";E={$_.GetOwner().Domain+"\"+$_.GetOwner().User}}
Works great, exactly what I need. But I thought that this should work as well:
Get-cimInstance win32_process|select name,
@{L="UserName";E={$_.getowner().user}}
But it doesn't:
[cid:[email protected]]
At this point I'm scratching my head, since I know that the CIM CMDLets can
invoke the GetOwner method:
[cid:[email protected]]
So I started looking into why. And found this. Kudos to Richard Siddaway, great
explanation of this:
https://blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell/
The main point is:
"CIM cmdlets use WSMAN to access remote computers. As a consequence, they
return inert objects. The WMI class methods aren't available on the object. "
YMMV
Christopher Bodnar
Enterprise Architect II, Corporate Office of Technology:Enterprise Architecture
and Engineering Services
Tel 610-807-6459
3900 Burgess Place, Bethlehem, PA 18017
[email protected]<mailto:>
[cid:[email protected]]
The Guardian Life Insurance Company of America
www.guardianlife.com<http://www.guardianlife.com/>
-----------------------------------------
This message, and any attachments to it, may contain information that is
privileged, confidential, and exempt from disclosure under applicable law. If
the reader of this message is not the intended recipient, you are notified that
any use, dissemination, distribution, copying, or communication of this message
is strictly prohibited. If you have received this message in error, please
notify the sender immediately by return e-mail and delete the message and any
attachments. Thank you.