Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Powershell - How to pull all AD accounts that end with a certain letter

Hi EE

I need some help turning this search to include all accounts that end with dc,d,pt,

all in one search instead of one search at a time ..

Get-ADUser -Filter {SamAccountName -like "*a"} -properties office,whencreated,CanonicalName | Select Samaccountname,whenCreated,office,CanonicalName | Export-CSV Accounts.csv
ASKER CERTIFIED SOLUTION
Avatar of Mike Kline
Mike Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can try
Get-ADUser -Filter {SamAccountName -like "*dc" -or SamAccountName -like "*d" -or SamAccountName -like "*pt"} -properties office,whencreated,CanonicalName | Select Samaccountname,whenCreated,office,CanonicalName | Export-CSV Accounts.csv

or

Get-ADUser -Filter * -properties office,whencreated,CanonicalName | ?{$_.SamAccountName -match "dc$|d$|pt$"} | Select Samaccountname,whenCreated,office,CanonicalName | Export-CSV Accounts.csv

Open in new window

Avatar of MilesLogan

ASKER

Thank you both !