简体   繁体   中英

Powershell get-service piped to stop-process

Get-Service | Stop-Process -Name WSearch -WhatIf

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:15 + Get-Service | Stop-Process -Name WSearch -WhatIf + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (fdPHost:PSObject) [Stop-Process], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand

Now from my understanding they both share the same property name "Name" so I should be able to pipe thru -Name, right?

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

So am I doing something wrong here?

Get-Service -Name wsearch | Stop-Service

will work. Filter first and pass the result through the pipeline.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM