Get-Service | Stop-Process -Name WSearch -WhatIf
Stop-Process:输入对象不能绑定到任何参数 该命令要么是因为命令不接受管道输入,要么是 输入及其属性与任何参数都不匹配 拿管道输入。在行:1 char:15 +获取服务|停止进程-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
我在这里做错了吗?
答案 0 :(得分:5)
Get-Service -Name wsearch | Stop-Service
会奏效。首先过滤并通过管道传递结果。