Jas*_*son 1 windows powershell
Get-Service | Stop-Process -Name WSearch -WhatIf
Run Code Online (Sandbox Code Playgroud)
Stop-Process:输入对象不能绑定到命令的任何参数,因为该命令不接受管道输入或输入及其属性与接受管道输入的任何参数都不匹配.在线:1字符:15 + Get-Service | Stop-Process -Name WSearch -WhatIf + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(fdPHost :PSObject)[Stop-Process],ParameterBindingException + FullyQualifiedErrorId:InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand
现在从我的理解,他们都共享相同的属性名称"名称",所以我应该能够通过-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
Run Code Online (Sandbox Code Playgroud)
我在这做错了吗?
Get-Service -Name wsearch | Stop-Service
Run Code Online (Sandbox Code Playgroud)
将工作.首先过滤并通过管道传递结果.