IADsGroup
The IADsGroup interface is designed to manage group membership data. It enables you to get member objects, test if a given object belongs to the group, and to add, or remove, an object to, or from, the group.
Inheritance: IADs
Methods
-
Method
-
Description
-
Add()
-
Adds a member to the group.
-
IsMember()
-
Determines if a directory service object is an immediate member of the group.
-
Members()
-
Retrieves a collection of the immediate members of the group.
-
Remove()
-
Removes the specified member from the group.
Properties
-
Property
-
Description
-
Description
-
Gets or sets the description of the group.
Details
Add()
Adds a member to the group.
void Add(string newObject)
Parameters
The newObject parameter specifies the ADS path of the object to add to the group.
Remarks
The method can be used only if the IAdmGroup2::MembershipType property is set to ADM_GROUPMEMBERSHIPTYPE_ASSIGNED.
Examples
The following code sample adds user John Smith to the SalesGroup group.
- Powershell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the group $groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" $group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0) # Add user 'John Smith' to group 'SalesGroup' $userDN ="CN=John Smith,CN=Users,DC=domain,DC=com" $group.Add("Adaxes://$userDN")
- C#
-
using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the group const string groupPath = "Adaxes://CN=SalesGroup,CN=Groups,DC=domain,DC=com"; IADsGroup group = (IADsGroup)service.OpenObject( groupPath, null, null, 0); // Add user 'John Smith' to group 'SalesGroup' const string userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com"; group.Add(userPath); } }
IsMember()
Determines if a directory service object is an immediate member of the group. This method does not verify membership in nested groups.
bool IsMember(string member)
Parameters
The member parameter specifies the ADS path of the directory object to verify membership.
Remarks
The method will only work correctly if the group and the object are in the same domain. If the object is in a different domain than the group, this method always returns false
. If the group and the object are in different domains, use the IAdmGroup interface.
Examples
The following code sample adds user John Smith to the SalesGroup group and then reports that the user is now a member of the group.
- Powershell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the group $groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" $group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0) # Add user 'John Smith' to group 'SalesGroup' $userDN = "CN=John Smith,CN=Users,DC=domain,DC=com" $group.Add("Adaxes://$userDN") # Report that the user is now a member of the group Write-Host $group.IsMember("Adaxes://$userDN") # should be TRUE
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the group const string groupPath = "Adaxes://CN=SalesGroup,CN=Groups,DC=domain,DC=comm"; IADsGroup group = (IADsGroup)service.OpenObject( groupPath, null, null, 0); // Add user 'John Smith' to group 'SalesGroup' const string userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com"; group.Add(userPath); // Report that the user is now a member of the group Console.WriteLine(group.IsMember(userPath)); // should be TRUE } }
Members()
Retrieves a collection of the immediate members of the group. The collection does not include the members of other groups that are nested within the group. If you want to get a collection of all members, including members of the nested groups, use the IAdmGroup interface.
IADsMembers Members()
Examples
The following code sample enumerates all members of a group.
- Powershell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the group $groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" $group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0) # Enumerate all members of the group foreach($member in $group.Members()) { Write-Host $member.Name }
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the group const string groupPath = "Adaxes://CN=SalesGroup,CN=Groups,DC=domain,DC=com"; IADsGroup group = (IADsGroup)service.OpenObject( groupPath, null, null, 0); // Enumerate all members of the group foreach (IADs member in group.Members()) { Console.WriteLine(member.Name); } } }
Remove()
Removes the specified member from the group. The operation does not remove the group object itself even when there is no member remaining in the group.
void Remove(string objectToRemove)
Parameters
The objectToRemove parameter specifies the ADS path of the object to remove from the group.
Remarks
The method can be used only if the IAdmGroup2::MembershipType property is set to ADM_GROUPMEMBERSHIPTYPE_ASSIGNED.
Examples
The following code sample removes a user account from a group.
- Powershell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") # Connect to the Adaxes service $ns = New-Object("Softerra.Adaxes.Adsi.AdmNamespace") $service = $ns.GetServiceDirectly("localhost") # Bind to the target group $groupDN = "CN=SalesGroup,CN=Groups,DC=domain,DC=com" $group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0) # Remove a user account from a group $userDN = "CN=John Smith,CN=Users,DC=domain,DC=com" $group.Remove("Adaxes://$userDN")
- C#
-
using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { // Connect to the Adaxes service AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Bind to the target group const string groupPath = "Adaxes://CN=SalesGroup,CN=Groups,DC=domain,DC=com"; IADsGroup group = (IADsGroup)service.OpenObject( groupPath, null, null, 0); // Remove a user account from a group const string userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com"; group.Remove(userPath); } }
Description
Gets or sets the description of the group.
- Type:
- string
- Access:
- Read/Write
Requirements
Minimum required version: 2009.1