我使用以下代码通过Get-ADComputer
获取Active Directory信息,并且工作正常
$computersFilter= "(&(operatingSystem=*Windows 7*)(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))"
$computers= Get-ADComputer -LDAPFilter $computersFilter -Property LastLogonDate | Select-Object Name, OperatingSystem,LastLogonDate
$computers | Select Name, LastlogonDate, OperatingSystem | Export-Csv $ServiceTagsPath -NoTypeInformation
我还要检索操作系统高于Windows 7 (Windows 8,8.1和Windows 10)的计算机,但当我更改过滤器时,这样:
(&(operatingSystem=*Windows 7*)(operatingSystem=*Windows 8*)(operatingSystem=*Windows 10*) ...
没有任何内容返回$computers
变量
那么这样做的正确方法是什么?
答案 0 :(得分:0)
您定义$computersFilter
的方式,如果您查看它的类型,您会发现它的类型为string
。因此它不会返回任何东西。
PS C> $computersFilter = "(&(operatingSystem=*Windows7*))(name=*-*)(!name=V7-*)(!name=*-none)(!name=*-oncall)(!name=*-blackbaud)(!name=sc-win7-1)(!name=ut-swclient-01))"
PS C> $computersFilter.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
应该将 $computersFilter
声明为数组,以便针对对象集合评估-LDAPFilter
参数,如下所示 -
PS C>$computersFilter = @("operatingSystem=*Windows7*", "name=*-*", "!name=V7-*", "!name=*-none", "!name=*-oncall", "!name=*-blackbaud", "!name=sc-win7-1", "!name=ut-swclient-01")
PS C> $computersFilter.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array