Hal-itosis
asked on
How to get a list of Organisational Units from AD with only 4 characters in their name
Hi,
Wondering if anyone could help me with a command set that would output all the canonical names of OU's that have exactly 4 characters in their name?
Wondering if anyone could help me with a command set that would output all the canonical names of OU's that have exactly 4 characters in their name?
Oh if you want just the names you can add | %{$_.Name} to the end of that last command.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry I gave you sites before, fingurs quicker than the mind. Building off Guy's comment:
Get-ADOrganizationalUnit -Filter * | Where {$_.Name.Length -eq 4} | %{$_.Name}
I'm pretty sure name and CN are always the same. .
Get-ADOrganizationalUnit -Filter * | Where {$_.Name.Length -eq 4} | %{$_.Name}
I'm pretty sure name and CN are always the same. .
ASKER
Excellent, thanks for the idea's.
What met my criteria exactly was:
Get-ADOrganizationalUnit -Filter * | Where {$_.Name.Length -eq 4} | Select DistinguishedName
I tried the variations with Get-ADOrganizationalUnit cmmdlet but I'm no good with the "Where {$_.Name.Length -eq 4" stuff.
Thanks a lot to you both. Guy Lidbetter for the exact answer.
What met my criteria exactly was:
Get-ADOrganizationalUnit -Filter * | Where {$_.Name.Length -eq 4} | Select DistinguishedName
I tried the variations with Get-ADOrganizationalUnit cmmdlet but I'm no good with the "Where {$_.Name.Length -eq 4" stuff.
Thanks a lot to you both. Guy Lidbetter for the exact answer.
Just though providing distinguishedname (CN) rather than just name would be more useful as you can see where the actual OU is located.
Import-Module ActiveDirectory
Get-ADSite | ?{$_.Name.Length -eq 4}
Note: you must have at least the RSAT tools loaded to get access to the module.
Hope that helps.
Steven