Solved

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

Posted on 2015-02-20
6
65 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

628 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