我正在尝试对一个脚本进行排序,该脚本将检索进程的所有实例以及进程各自的所有者。
我有一个脚本来获取进程名称和开始时间:
get-process -name notepad | select-object starttime,name
我有一个脚本来获取进程所有者:
$process = (Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'")
$owner = Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user | ft -HideTableHeaders
但是,当我创建一个属性并将其全部放在一起时,我得到的结果几乎可以肯定与格式有关:
$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...
通过阅读,它似乎与 $owner 的格式相同,但我一生都无法弄清楚。有任何想法吗?
Format-Table
将您的对象转换为格式化字符串,这对于显示和输出到文本文件非常有用,但会弄乱您想要传递的任何对象。因此,请小心使用任何格式命令。另外,因为您可能想扩展users
财产。
$process = (Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'")
$owner = Invoke-CimMethod -InputObject $process -MethodName GetOwner | select -ExpandProperty user
get-process -name notepad | select-object starttime,name,@{n='Owner';e={$owner}}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)