Solved

Filtering sAMAccountname by case in Powershell

Posted on 2014-01-14
3
454 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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now