Solved

Get all users in a certain OU only

Posted on 2015-01-28
4
57 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

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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