Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to exclude an OU during a search?

$
0
0

I have this code that works to move old computer accounts to an inactive OU.  

 

$Inactive_computer_OU = 'OU=InactiveComputers,DC=Acme,DC=com'

$sourceOU = 'Acme.com/WorkstationComputers'

Set-QADPSSnapinSettings -DefaultSizeLimit 0

$old = (Get-Date).AddDays(-45).ToFileTime()

$ldapFilter = '(pwdLastSet<={0})' -f $old

Get-QADComputer -LdapFilter $ldapFilter -SearchRoot $sourceOU -IncludedProperties pwdLastSet -SizeLimit 9000 | Move-QADObject -NewParentContainer $Inactive_computer_OU

 

But under $sourceOU = 'Acme.com/WorkstationComputers' I have a sub-OU located here:

'Acme.com/WorkstationComputers/XenDesktops'

 

I need to exclude this 1 OU from what this script does.  How do you handle that?  


Viewing all articles
Browse latest Browse all 6937

Trending Articles