我想要获取我的域中所有已启用且具有 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
最佳答案
您可以在过滤器内使用-notlike
运算符,因此不需要where
语句。请参阅Get-ADComputer reference on technet .
正如我提到的,除了将 -or
运算符更改为 -and
之外,我还将所有条件放入过滤器中,最终结果如下:
Get-ADComputer -filter {
Enabled -eq $True -and
OperatingSystem -like '*2003*' -and
Name -notlike 'PING*' -and
Name -notlike 'PICT*' -and
Name -notlike 'PIRE*'
} | Select Name
关于powershell - 如何从 Get-ADComputer 结果中排除特定名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27491952/