Check if a group exists in Active directory

Check if a group exists in Active directory

Note: To add or read properties from an Active Directory group you need to have special username and password like an Active Directory admin.

DirectoryEntry addGroup;
string folderPath = "LDAP://CN=" + folderName + ",";
folderPath += "OU=SharedFolder,OU=Groups,DC=aaaaaa,DC=com";

protected Boolean chkGroupExistence(DirectoryEntry addGroup)
    {
        // chk if the requested AD group is available and a proper AD Group object is formed.    

        bool groupExists = true;
        try
        {
            if (addGroup.SchemaClassName == "group")
            { groupExists = true; }
        }
        catch (Exception)
        {
            groupExists = false;
        }
        return groupExists;
    }

Leave your comments below.

No comments: