2016-10-02 2 views
0

私は、コードを作業するPowershellの殺害プロセス - 私の文字列に何が問題なのですか?

Get-Process firefo* | Stop-Process 

であることを知っているしかし、私の最初の推測では、それは動作しませんでした

Get-Process | findstr firefox | Stop-Process 

ました。

Stop-Process : The input object cannot be bound to any parameters for the command 
either because the command does not take pipeline input or the input and its 
properties do not match any of the parameters that take pipeline input. 
At line:1 char:33 
+ Get-Process | findstr firefox | Stop-Process 
+         ~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: ( 1379  317...    :PSObject) [Stop-Process], ParameterBindingException 
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand

私は

 1342  306 1228412 1279864 -1671 ...71,42 35912 firefox

その文字列を理解するには、プロセスを殺すために悪いですが、なぜ?

PS C:\Users\adamg> Get-Process firefo* 

Handles NPM(K) PM(K)  WS(K) VM(M) CPU(s)  Id ProcessName 
------- ------ -----  ----- ----- ------  -- ----------- 
    1342  306 1228412 1279864 -1671 ...71,42 35912 firefox 

上記の動作は、返信の列ヘッダーでもうまくいきます。

+0

あなたはコマンドレットの 'は、Get-ヘルプ-full'を見て、入力と出力オブジェクトを見ています。 dosコマンド 'findstr'はPowershellコマンドレットの入力として使用できない出力としてのみコンソールテキストを生成します。 – user4317867

答えて

2

findstrは、文字列出力を生成するコマンドラインユーティリティです。 Get-ProcessStop-Processが入力として期待するものであるProcessオブジェクトを出力します。また、プロセスIDのリストを処理することもできますが、フォーマットされた文字列をfindstrから解析することはできません。

PowerShellでは、通常はとにかくfindstrを使用しません。代わりにWhere-Objectフィルタを使用してください:

Get-Process | Where-Object { $_.ProcessName -like '*firefox*' } | Stop-Process 
関連する問題