Solved

Get all users in a certain OU only

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

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
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 …

717 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