Solved

How to get a list of Organisational Units from AD with only 4 characters in their name

Posted on 2015-02-20
6
60 Views
Last Modified: 2015-02-20
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?
0
Comment
Question by:Hal-itosis
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:nashiooka
ID: 40620895
Using PowerShelll with the AD module loaded so:

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
0
 
LVL 10

Expert Comment

by:nashiooka
ID: 40620896
Oh if you want just the names you can add | %{$_.Name} to the end of that last command.
0
 
LVL 13

Accepted Solution

by:
Guy Lidbetter earned 500 total points
ID: 40620899
Hi Hal-itosis ... (Nice Name)

Try this:

$OUs = Get-ADOrganizationalUnit -Properties * | select *
foreach ($OU in $OUs) {IF ($OU.Name.Length -eq 4) {Write-Host $OU.DistinguishedName}}

Open in new window


OR

 Get-ADOrganizationalUnit -Filter * | Where {$_.Name.Length -eq 4} | Select DistinguishedName

Open in new window


Regards

Guy
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 10

Expert Comment

by:nashiooka
ID: 40620906
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.  .
0
 
LVL 1

Author Closing Comment

by:Hal-itosis
ID: 40620916
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.
0
 
LVL 13

Expert Comment

by:Guy Lidbetter
ID: 40620917
Just though providing distinguishedname (CN) rather than just name would be more useful as you can see where the actual OU is located.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question