Solved

Get all users in a certain OU only

Posted on 2015-01-28
4
59 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
[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
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 84

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 37

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

726 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