Solved

Filtering sAMAccountname by case in Powershell

Posted on 2014-01-14
3
461 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 68

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 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

25 Experts available now in Live!

Get 1:1 Help Now