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
LVL 2
MilesLoganAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike KlineCommented:
You are almost there just update your filter


Get-ADUser -Filter {SamAccountName -like "*dc"  -or samaccountname -like "*d"...and so on}

Thanks

Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SubsunCommented:
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

0
MilesLoganAuthor Commented:
Thank you both !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.