2015-01-01 33 views
0
Get-Service | Stop-Process -Name WSearch -WhatIf 

停止進程:輸入對象不能被綁定到任何參數 命令或者因爲該命令不採取管道輸入或 輸入和其屬性不匹配 進行流水線輸入的任何參數。在線:1 char:15 + Get-Service | Stop-Process -Name WSearch -WhatIf + ~~~~~~~~~~~~~~~~~~~~ + + + CategoryInfo:InvalidArgument: (FDPHOST:PSObject)[停止進程],ParameterBindingException + FullyQualifiedErrorId:InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand的powershell得到服務管道以停止處理

現在,從我的理解,他們都共享相同的屬性名稱 「姓名」,所以我應該能夠通過-Name管道,對吧?

PS C:\> Get-Service | gm 
    TypeName: System.ServiceProcess.ServiceController 
Name      MemberType Definition 
----      ---------- ---------- 
Name      AliasProperty Name = ServiceName 

get-help stop-process 

    -Name <String[]> 
     Specifies the process names of the processes to be stopped. You can type multiple process names (separated by commas) or use wildcard characters. 

     Required?     true 
     Position?     named 
     Default value     
     Accept pipeline input?  true (ByPropertyName) 
     Accept wildcard characters? true 

所以我在這裏做錯了什麼?

回答

3
Get-Service -Name wsearch | Stop-Service 

將工作。首先過濾並通過管道傳遞結果。

+2

或者你可以做'Stop-Service -Name wsearch'。 –