【发布时间】:2014-12-15 19:50:13
【问题描述】:
我想获取我的域中所有已启用的计算机,并且具有 2003 操作系统,并且计算机的名称不包含 ' ping 、 pict 、 pire ' 这是我所拥有的,但完全失败了:
Get-ADComputer -filter {(Enabled -eq $True) -and (OperatingSystem -like "*2003*")} -properties OperatingSystem | where {($_.Name -notlike 'PING*') -or ($_.Name -notlike 'PICT*') -or ($_.Name -notlike 'PIRE*')} | Select Name
【问题讨论】:
-
将
-or更改为-and(两者)会得到什么? -
定义“失败”。您会得到什么结果,这与您预期的结果有何不同?
-
您的条件应该是
-and,因为 PICT001 将匹配条件($_.Name -notlike 'PING*'),从而使条件的这一部分满足-or。你也可以用一点正则表达式来简化它:Where-Object { $_.Name -notmatch "^(PING|PICT|PIRE)"}或-notmatch "^PI(NG|CT|RE)"}
标签: powershell active-directory