【问题标题】:Powershell where clause filteringPowershell where子句过滤
【发布时间】:2014-03-04 04:44:19
【问题描述】:

我正在尝试使用 powershell 脚本过滤在服务器中运行的服务。但是语法似乎不正确

脚本

Get-Service -ComputerName $ServerName |Where-Object {$_.Name -like "DEX*" -or $_.Name -like "WORLD*" -or $_.Name -like "Entr *"}

突出显示的部分有问题。非常感谢任何帮助..

【问题讨论】:

  • 我看到的第一件事是您的示例缺少结束 }。运行此行时,您看到了哪些错误和/或意外行为?
  • } 添加了大括号。添加时错过了。
  • 它只是获取名称为“DEX*”的服务,其他部分被忽略

标签: powershell cmdlet


【解决方案1】:

Get-Service Name 属性中匹配服务的短名称。你不需要DisplayName 吗?

Get-Service -ComputerName $ServerName |Where-Object {$_.DisplayName -like "DEX*" -or $_.DisplayName -like "WORLD*" -or $_.DisplayName -like "Entr*"}

另外,您的服务简称或显示名称真的以 WORLDEntr 开头?

【讨论】:

  • 是的 JPBLanc 显示名称以 World 和 Entr.. 开头。谢谢
【解决方案2】:

一旦您知道您正在寻找显示名称,这是一种最短的方法:

 get-service -displayname DEX*,WORLD*,Entr*

【讨论】:

    猜你喜欢
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2016-07-02
    • 2021-08-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多