System.DirectoryServices.Protocol move user question
I want to move a user from one OU to a Different OU, and also to update a few attributes using System.DirectoryServices.Protocol, but I'm having a very hard time finding any code samples for anything except searching.
Can anyone please post some code samples and or links to c开发者_如何学Pythonode samples/tutorials for these two operation in S.DS.P?
Thanks,
Cal-
Below is an example from a very good source of c# Active Directory examples at Howto: (Almost) Everything In Active Directory via C#
//Move an object from one ou to another
DirectoryEntry eLocation = new DirectoryEntry("LDAP://" + objectLocation);
DirectoryEntry nLocation = new DirectoryEntry("LDAP://" + newLocation);
string newName = eLocation.Name;
eLocation.MoveTo(nLocation, newName);
nLocation.Close();
eLocation.Close();
//Modify an attribute of a user object
DirectoryEntry user = new DirectoryEntry(userDn);
int val = (int)user.Properties["userAccountControl"].Value;
user.Properties["userAccountControl"].Value = val & ~0x2;
user.CommitChanges();
user.Close();
You can have a look to the article called Introduction to System.DirectoryServices.Protocols inside you'll find a shortcut to download MS_Sample_Pack_For_SDSP.EXE which is a solution with many examples :
MoveRenameObject server_or_domain_name originalDn newParentDn objectName
may be useful for you.
精彩评论