by taotao07 at 2013-02-06 10:53:30
So, here’s an interesting one for you… Currently we’re using abc1234 format for our usernames, so three letters and four digits. I just noticed that someone has been creating new users with abc123 format, so three letters and three digits. What would be a query to list only users with abc123 UID format? I’ve tried several where-object {$.samaccountname -like …} combinations but I can’t seem to come up with the right one. Any help is greatly appreciated.by ArtB0514 at 2013-02-06 11:54:52
Thanks!
Instead of -Like, use -Match and a regex.by taotao07 at 2013-02-06 12:05:08Where-Object {$
.samAccountName -match "[1]{3}\d{3}$"}
Where[list]
^ – start of string
[a-zA-Z] – include all lower and upper case letters
{3} – repeat exactly 3 times
\d – any digit
{3} – repeat exactly 3 times
$ – end of string[/list]
For an introduction to regular expressions, see http://msdn.microsoft.com/en-us/library/ms972966.aspx.
Works like a charm, thank you!by ArtB0514 at 2013-02-06 13:46:07
You’re very welcome.
a-zA-Z ↩︎