Get-QADComputer -LdapFilter & NOT operator

Posted by dboftlp on Server Fault See other posts from Server Fault or by dboftlp
Published on 2010-04-13T20:11:39Z Indexed on 2010/04/13 20:13 UTC
Read the original article Hit count: 278

Filed under:
|

I'm having issues excluding an OU from my LDAP filter

$DaysAgo = (Get-Date).AddDays(-31)
$ft = $DaysAgo.ToFileTime()

Get-QADComputer -SizeLimit 0 -IncludeAllProperties
-SearchRoot 'DC=My,DC=Domain,DC=Local'
-LdapFilter "(&(objectcategory=computer)(lastLogonTimeStamp<=$ft)
(!(ou:dn:=DisabledPCs))(|(operatingsystem=Windows 2000 Professional)
(operatingSystem=Windows XP*)(operatingSystem=Windows 7*)
(operatingSystem=Windows Vista*)(operatingsystem=Windows 2000 Server)
(operatingsystem=Windows Server*)))"

I'm looking to query for all Windows OS systems that haven't logged in to AD for more than 31 days & that are not already in the OU "DisabledPCs", which is where I'll be moving them to.

When I run it now, I'm getting all the systems I'm looking for, including those in the "DisabledPCs" OU... I've tried several variations including:

(&(!(ou:dn:=DisabledPCs)))

As well as putting it in different locations in the filter (not that I thought it would make a difference, but I obviously don't know that...)

Thanks in advance for any help,

-dboftlp

© Server Fault or respective owner

Related posts about powershell

Related posts about ldap