CaussyR
asked on
Export Computer Accounts from Certain OUs, using Powershell ?
Does anyone have a script available that can extract computer accounts from OUs and not from others ? What I would like to do is to run a PowerShell script to extract computer accounts, which I have done. This pulled out all computer accounts, but what I would like to do, is to extract computer accounts from all OUs apart from the Computer \ Test \ Dev OUs.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Given that we're qualifying the distinguishedName you can do this based on all or part of the path.
For example, if you wanted to exclude a root OU called Test you could do this in the Where-Object statement:
You can look for nested OUs in much the same way:
Chris
For example, if you wanted to exclude a root OU called Test you could do this in the Where-Object statement:
$_.DistinguishedName -match 'OU=Test,DC=yourdomain,DC=com$'
It's a regular expression matching anything at the end of the string so we look for yourdomain.com/Test in effect.You can look for nested OUs in much the same way:
$_.DistinguishedName -match 'OU=Test2,OU=Test1,OU=Test'
Is that what you mean?Chris
ASKER
Test > Test1 > Test2