Wednesday, 15 April 2015

windows - Update user info in AD -



windows - Update user info in AD -

i have posted question before, may not described problem, hence re-rewrite question, hoping may understand it.

in windows server, there around 1500 users, user info in active directory not right , needs updated. e-mail field should updated, example, current email tom.chan@email.com, want alter "user name" + email.com

for example:

tom.chan@email.com ==> user1@email.com ; amy.yuen@email.com ==> user2@email.com ; jacky.hung@email.com ==> user3@email.com

could can help give advice? give thanks in advance.

you can utilize principalsearcher , "query-by-example" principal searching:

// create domain context using (principalcontext ctx = new principalcontext(contexttype.domain)) { // define "query-by-example" principal - here, search userprincipal // lastly name (surname) starts "a" userprincipal qbeuser = new userprincipal(ctx); qbeuser.surname = "a*"; // create principal searcher passing in qbe principal using (principalsearcher srch = new principalsearcher(qbeuser)) { // find matches foreach(var found in srch.findall()) { // here need update - i'm not sure *which* // attribute mean "username" - debug code , see // advertisement attribute want utilize userprincipal founduser = found userprincipal; if(founduser != null) { string newemail = founduser.samaccountname + "@email.com"; founduser.emailaddress = newemail; founduser.save(); } } } }

using approach, loop on users , update them - again: i'm not exclusively sure understand want utilize new e-mail address..... maybe need adapt needs.

also: recommend not doing entire user base of operations @ once! run in groups, e.g. ou, or initial letter of lastly name or - don't mass update of 1500 users @ 1 time - break downwards manageable pieces.

if haven't - absolutely read msdn article managing directory security principals in .net framework 3.5 shows nicely how create best utilize of new features in system.directoryservices.accountmanagement. or see msdn documentation on system.directoryservices.accountmanagement namespace.

of course, depending on need, might want specify other properties on "query-by-example" user principal create:

displayname (typically: first name + space + lastly name) sam business relationship name - windows/ad business relationship name user principal name - "username@yourcompany.com" style name

you can specify of properties on userprincipal , utilize "query-by-example" principalsearcher.

windows active-directory

No comments:

Post a Comment