我有一个PowerShell函数,它返回一个可执行名称的列表(带有文件扩展名),如果它们正在运行,我会试图杀死其中任何一个,但是没有取得多大的成功。下面是我使用的命令:
Get-Executable-Names `
| where { $_ -match ".exe" } `
| foreach { $_ -replace ".exe" } `
| foreach { ps $_ } `
| kill如果我将Get-Executable名称的输出存储在变量中并显示其内容,它将显示为:
Path
----
A.exe
B.exe
C.exePowerShell正在报告此错误:
Get-Process :无法找到名称为"@{Path=A}“的进程.验证进程名并再次调用cmdlet。
-replace操作似乎将管道数据更改为以下格式:
@(Path=A)
@(Path=B)
@(Path=C)但我不明白。我肯定我只是误解了PowerShell的对象模型,但是我忽略了什么呢?
发布于 2010-02-24 18:44:56
尝试在调用GetExecutableNames之后添加以下内容
%{ $_.Path }全答
Get-Executable-Names
| where { $_ -match ".exe" }
| %{ $_.Path }
| %{ $_ -replace ".exe" }
| %{ ps $_ }
| killhttps://stackoverflow.com/questions/2328525
复制相似问题