我正在尝试获取进程的所有者,代码:
(Get-WmiObject -class win32_process | where{$_.ProcessName -eq 'explorer.exe'}).getowner() | Foreach-Object user | out-string**这在win8下运行得很好,但在win7中我得到了这个消息:
ForEach-Object : Cannot bind parameter 'Process'. Cannot convert the "user" val
ue of type "System.String" to type "System.Management.Automation.ScriptBlock".
At C:\Program Files (x86)\Advanced Monitoring Agent GP\scripts\9660.ps1:1 char:
108
+ (Get-WmiObject -class win32_process | where{$_.ProcessName -eq 'explorer.exe'
}).getowner() | Foreach-Object <<<< user | out-string
+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], Parameter
BindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh
ell.Commands.ForEachObjectCommand请帮帮我!谢谢你抽出时间来。
发布于 2014-03-25 22:30:28
使用select -expand user而不是foreach-object user。这等同于做foreach-object { $_.user },这可能就是你想要做的。对语法灵活性的改进允许您在更高版本的powershell中进行首次尝试。
https://stackoverflow.com/questions/22637434
复制相似问题