Get all users in a certain OU only

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 !
LVL 2
MilesLoganAsked:
Who is Participating?
 
MaheshConnect With a Mentor ArchitectCommented:
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
 
Sam Simon NasserCONSULTANT/DIRECTORCommented:
you can use powershell, by running this command
get-qadgroup GroupName| get-qadmemberof

Open in new window

0
 
oBdAConnect With a Mentor Commented:
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
 
MilesLoganAuthor Commented:
Sorry guys .. I thought I had closed this ..  thank you for your assistance .
0
All Courses

From novice to tech pro — start learning today.