【问题标题】:Powershell get-service piped to stop-processPowershell get-service 通过管道传输到停止进程
【发布时间】:2015-02-28 06:18:39
【问题描述】:
Get-Service | Stop-Process -Name WSearch -WhatIf

Stop-Process : 输入对象不能绑定到任何参数 该命令要么是因为该命令不接受管道输入,要么 输入及其属性不匹配任何参数 接受管道输入。在行:1 字符:15 + 获取服务 |停止进程 -Name WSearch -WhatIf + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (fdPHost:PSObject) [Stop-Process], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand

现在据我了解,它们都共享相同的属性名称“Name”,所以我应该能够通过 -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

所以我在这里做错了吗?

【问题讨论】:

    标签: windows powershell


    【解决方案1】:
    Get-Service -Name wsearch | Stop-Service
    

    会起作用。先过滤,然后通过管道传递结果。

    【讨论】:

    • 或者你可以做Stop-Service -Name wsearch
    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 2013-05-31
    相关资源
    最近更新 更多