【问题标题】:Filtering Powershell output过滤 Powershell 输出
【发布时间】:2013-06-05 12:00:22
【问题描述】:

我正在尝试过滤以下 PS 脚本的输出;

我们使用的服务器名称如下:

SRV-APP-001, PRD-APP-001, TST-APP-001 等等……

$strCategory = "computer" 
$strOperatingSystem = "Windows*Server*" 

$objDomain = New-Object System.DirectoryServices.DirectoryEntry 

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher 
$objSearcher.SearchRoot = $objDomain

$objSearcher.Filter = ("OperatingSystem=$strOperatingSystem") 

$colProplist = "name" 
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} 

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults) 
    { 
    $objComputer = $objResult.Properties;  
    $objComputer.name
    }

此脚本的输出是域中的所有服务器。

但我只想查看以“SRV”或“PRD”开头的服务器

| where { $_name -like "SRV*"}$objComputer.name 部分之后无法真正工作。

提前谢谢你

【问题讨论】:

标签: powershell filter output


【解决方案1】:

将过滤器更改为:

"(|(name=SRV*)(name=PRD*))(OperatingSystem=Windows*Server*)"

【讨论】:

  • 嗯,我并没有真正让它与那行代码或它的示例一起工作。我必须在 '$objSearcher.Filter = ("OperatingSystem=$strOperatingSystem")' 之后/中应用它吗?
  • $objSearcher.Filter = "(|(name=SRV*)(name=PRD*))(OperatingSystem=WindowsServer)"
猜你喜欢
  • 2021-10-15
  • 2016-05-21
  • 1970-01-01
  • 2014-06-15
  • 2021-07-02
  • 1970-01-01
  • 2012-12-15
  • 2017-12-31
  • 1970-01-01
相关资源
最近更新 更多