Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Can I use a variable in and LdapFilter with Get-QADComputer? i.e.:

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

$ft = $31DaysAgo.ToFileTime()

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter '(&(objectcategory=computer) `
(pwdLastSet<=$ft)(|(operatingsystem=Windows 2000 Professional) `
(operatingSystem=Windows XP*)(operatingSystem=Windows 7*) `
(operatingSystem=Windows Vista*)(operatingsystem=Windows 2000 Server) `
(operatingsystem=Windows Server*)))'

If not, how else can I filter out the pwdLastSet filter? Should I just do it after in a pipe? i.e.:

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter '(&(objectcategory=computer) `
(|(operatingsystem=Windows2000 Professional)(operatingSystem=Windows XP*) `
(operatingSystem=Windows7*)(operatingSystem=Windows Vista*) `
(operatingsystem=Windows 2000 Server)(operatingsystem=Windows Server*)))' `
| Where {$_.pwdLastSet -gt $ft}

or even

| Where {$_.LastLogonTimeStamp -gt $ft}

I know this is going to be slower, but if I have to, I'll go this route.

Also, if anyone know's off the top how to time how long a code snippet would take to run, that hint would be greatly appreciated =) ktxbye

Thanks, -dboftlp

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Your first query should work, but you'll need to put the LdapFilter in double quotes " - PowerShell doesn't expand variables within single quotes.

$StComps = Get-QADComputer -SizeLimit 0 -IncludeAllProperties -SearchRoot `
'DC=MY,DC=DOMAIN,DC=LOCAL' -LdapFilter "(&(objectcategory=computer) `
(pwdLastSet<=$ft)(|(operatingsystem=Windows 2000 Professional) `
(operatingSystem=Windows XP*)(operatingSystem=Windows 7*) `
(operatingSystem=Windows Vista*)(operatingsystem=Windows 2000 Server) `
(operatingsystem=Windows Server*)))"
share|improve this answer
    
Yep, Shay Levy said the same thing on PowerGui.org forums. I'm finally getting in to the guts of PoSh and things like this are very important to my understanding and formatting scripts. Thanks, -dboftlp –  dboftlp Apr 1 '10 at 19:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.