Solved

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

Posted on 2015-02-20
6
57 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:nashiooka
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now