Jason
Jason

Reputation: 821

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?

Upvotes: 1

Views: 2107

Answers (1)

David Brabant
David Brabant

Reputation: 43499

Get-Service -Name wsearch | Stop-Service

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

Upvotes: 5

Related Questions