public AddUserToGroup ( System.DirectoryServices.AccountManagement.UserPrincipal adUser, string groupName ) : void | ||
adUser | System.DirectoryServices.AccountManagement.UserPrincipal | User to add |
groupName | string | Group to which the user should be added |
Результат | void |
public void AddUserToGroup(UserPrincipal adUser, string groupName)
{
GroupPrincipal g = GetOrCreate(groupName);
g.Members.Add(adUser);
g.Save();
}
/// <summary> /// Add the ADUser to a group /// </summary> /// <param name="groupName">The name of the group to which the user should be added</param> public void addToGroup(string groupName) { try { _connection.AddUserToGroup(_sourceUser, groupName); } catch (Exception ex) { string msg = String.Format("Error adding user '{0}' to group '{1}': '{2}'", this.DisplayName, groupName, ex.Message); Console.WriteLine(msg); throw new ADException(msg, ex); } }