Solved

Filtering sAMAccountname by case in Powershell

Posted on 2014-01-14
3
476 Views
Last Modified: 2014-01-14
So I have been beating my head against a wall trying to figure this one out.

I need to run a script that will return to me any sAMAccountname in AD that is in all uppercase.  I believe that this is getting closer, but the operator is not supported...

get-aduser -Filter {sAMAccountname -cmatch'^[A-Z]+$'} -Properties name,samaccountname

Any input?

Thanks!
0
Comment
Question by:anim8rs
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39780014
You can only use the following operators with -Filter
"-eq" | "-le" | "-ge" | "-ne" | "-lt" | "-gt"| "-approx" | "-bor" | "-band" | "-recursivematch" | "-like" | "-notlike"

Open in new window


Try with Where-Object
Get-aduser -Filter * | ? {$_.sAMAccountname -cmatch'^[A-Z]+$'} 

Open in new window

0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39780161
Of course you could also use
Get-aduser -Filter * | ? {$_.sAMAccountname -ceq $_.sAMAccountname.ToUpper() } 

Open in new window

but that doesn't change anything. Major issue is that the check has to happen on the client, and no cmdlet filter expression can be used.
0
 

Author Closing Comment

by:anim8rs
ID: 39780195
Worked like a champ!  Thanks!  I had tried a variation of that, but looks like I had a problem with syntax.

Thanks a ton!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 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