c# - How to query Active Directory for a user whose name contains a dollar sign ($)? -
i have code snippet searches locally-defined windows user :
using (principalcontext context = new principalcontext(contexttype.machine)) { using (principal queryfilter = new userprincipal(context) { name = accountname }) { using (principalsearcher searcher = new principalsearcher(queryfilter)) { var principal = searcher.findone(); ... } } }
the code works fine if accountname
contains normal alphanumerics, (eg "testuser"). however, if name contains dollar sign (eg "test$user"), findone()
returns nothing.
i suspect $ being interpreted kind of metacharacter. there way of preventing happening, interpreted literally?
if you're looking single entry - try this:
userprincipal user = userprincipal.findbyidentity(context, "test$user");
maybe works?
Comments
Post a Comment