Solved

Get all users in a certain OU only

Posted on 2015-01-28
4
56 Views
Last Modified: 2015-02-10
Hi EE

I tried different variations -SearchBase and $_.samaccountname.length -eq 8 but cant figure it out . ..

I need to pull all AD users from a certain OU that are 8 characters long only .
Need the output file to have the SamAccountName,Name,CanonicalName

Thank you for all the help !
0
Comment
Question by:MilesLogan
4 Comments
 
LVL 10

Expert Comment

by:Sam Simon Nasser
ID: 40576826
you can use powershell, by running this command
get-qadgroup GroupName| get-qadmemberof

Open in new window

0
 
LVL 83

Assisted Solution

by:oBdA
oBdA earned 250 total points
ID: 40576885
Assuming you have W2k8R2 (with the Microsoft AD Cmdlets):
$SearchOU = "OU=SomeOU,OU=Whatever"
$SearchSamLength = 8
$Properties = "SamAccountName", "Name", "CanonicalName"
$DefaultNamingContext = ([ADSI]"LDAP://RootDSE").DefaultNamingContext
Get-ADUser -SearchBase "$($SearchOU),$($DefaultNamingContext)" -Filter * -Properties $Properties | ? {$_.SamAccountName.Length -eq $SearchSamLength} | Select -Property $Properties

Open in new window

0
 
LVL 35

Accepted Solution

by:
Mahesh earned 250 total points
ID: 40577191
Try below from elevated AD PowerShell Module
 
$OU = "OU=Test,DC=domain,DC=com"
Get-ADUser -Filter * -SearchBase $OU | Select SamAccountName,Name,cn | Where-Object {$_.SamAccountName.Length -eq 8} | Export-Csv C:\output.csv

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 40602163
Sorry guys .. I thought I had closed this ..  thank you for your assistance .
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

706 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

17 Experts available now in Live!

Get 1:1 Help Now