我的脚本中有下面的LDAP查询(来自斯图尔特),它返回Get-ADComputer for Windows 7中的所有计算机,但有一些例外。
$computersFilter= "(&(operatingSystem=*Windows 7*)(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))" 它可以很好地工作,下面调用Get-ADComputer
$computers= Get-ADComputer -LDAPFilter $computersFilter -Property LastLogonDate | Select-Object Name,LastLogonDate
$computers | Select Name, LastlogonDate | Export-Csv $ServiceTagsPath -NoTypeInformation但是,我希望让我的查询返回所有使用Windows7和以上的计算机,但是当我像这样更改它时:
(&(operatingSystem=*Windows 7*)(operatingSystem=*Windows 8*)(operatingSystem=*Windows 10*)$computers变量中没有返回任何内容。
那么,编写LDAP查询以返回所有操作系统版本的Windows 7及更高版本的正确方法是什么?
发布于 2018-04-20 08:27:25
经过罗伯在评论中的一些帮助和进一步的研究,我发现正确的方法是使用OR,而操作符是|。
就像这样:
$computersFilter= "(&(|(operatingSystem=*Windows 7*)"
$computersFilter+= "(operatingSystem=*Windows 8*)"
$computersFilter+= "(operatingSystem=*Windows 8.1*)"
$computersFilter+= "(operatingSystem=*Windows 10*))"
$computersFilter+= "(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)"
$computersFilter+= "(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))"
$computers= Get-ADComputer -LDAPFilter $computersFilter
-Property * | Select-Object Name, OperatingSystem, LastLogonDate
$computers | Select Name, OperatingSystem, LastLogonDate |
Export-Csv $ServiceTagsPath -NoTypeInformation参考文献:
https://stackoverflow.com/questions/49916324
复制相似问题