Aggiunta di membri a un gruppo

Quando viene creato un gruppo, è necessario aggiungere i membri. In questo argomento viene descritto come aggiungere membri a un gruppo.

È possibile aggiungere membri a un gruppo aggiungendo il nome distinto del membro all'attributo member del gruppo. Per ulteriori informazioni sull'attributo member nello schema Active Directory, vedere l'argomento relativo in MSDN Library all'indirizzo https://go.microsoft.com/fwlink/?LinkID=27252 (informazioni in lingua inglese). Questa operazione può essere eseguita con il metodo Add o AddRange.

Per aggiungere un singolo membro a un gruppo, aggiungere il nome distinto del membro alla proprietà member nell'oggetto gruppo utilizzando il metodo Add.

Nota:
Negli esempi riportati di seguito sono richieste la versione 1.0 Service Pack 3 e successive di .NET Framework o la versione 1.1 Service Pack 1 e successive di .NET Framework.

Nell'esempio di codice C# riportato di seguito viene illustrato come aggiungere un singolo membro a un gruppo.

// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// Add the user to the group.
group.Properties["member"].Add(userDN);

// Commit the changes to the group.
group.CommitChanges();

Nell'esempio di codice Visual Basic .NET riportato di seguito viene illustrato come aggiungere un singolo membro a un gruppo.

' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' Add the user to the group.
group.Properties("member").Add(userDN)

' Commit the changes to the group.
group.CommitChanges()

Per aggiungere più membri a un gruppo in una sola operazione, aggiungere i nomi distinti dei membri alla proprietà member nell'oggetto gruppo utilizzando il metodo AddRange.

Nell'esempio di codice C# riportato di seguito viene illustrato come aggiungere più membri a un gruppo.

// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// To add multiple users to a group, use the AddRange method.
group.Properties["member"].AddRange(new string[] {userDN1, userDN2});

// Commit the changes to the group.
group.CommitChanges();

Nell'esempio di codice Visual Basic .NET riportato di seguito viene illustrato come aggiungere più membri a un gruppo.

' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' To add multiple users to a group, use the AddRange method.
group.Properties("member").AddRange(New String() {userDN1, userDN2})

' Commit the changes to the group.
group.CommitChanges()

Vedere anche

Riferimenti

PropertyValueCollection
System.DirectoryServices

Concetti

Gestione di gruppi

Send comments about this topic to Microsoft.

Copyright © 2007 Microsoft Corporation. Tutti i diritti riservati.