Quantcast
Channel: Scripting Blog
Viewing all articles
Browse latest Browse all 2129

PowerTip: How to detect a valid Active Directory user name using regular expressions

$
0
0

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how use regex to detect if a string is a valid Active Directory user name.

Hey, Scripting Guy! Question The invalid characters for an Active Directory user name are /\[:;|=,+*?<>]\ and . How do I tell if a string is a valid Active Directory user name?

 

Hey, Scripting Guy! Answer You can treat this array of characters as a pattern and see if they exist within the string

$questionablestring -match "[$([Regex]::Escape('/\[:;|=,+*?<>') + '\]' + '\"')]"

You’ll have to manually escape ] and because [regex]::escape() is a bit quirky.

The Doctor


Viewing all articles
Browse latest Browse all 2129

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>