I'm trying to sort a script that will retrieve all instances of a process and the respective owners of the process.
I have a script to get the process name and start time:
get-process -name notepad | select-object starttime,name
I have a script to get the process owner:
$process = (Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'")
$owner = Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user | ft -HideTableHeaders
However, when I create a property and put it all together, I get a result which I'm almost certain relates to formatting:
$process = (Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'")
$owner = Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user | ft -HideTableHeaders
get-process -name notepad | select-object starttime,name,@{n='Owner';e={$owner}}
Result:
StartTime Name Owner
--------- ---- -----
31/01/2017 14:44:57 notepad {Microsoft.PowerShell.Commands.Internal.Format.FormatStartData, Mic...
From reading around, it appears to be with the formatting of $owner, but I can't for the life of me figure it out. Any ideas?