Exemple #1
0
        public static void CreateNewProperty()
        {
            // create a new property object
            ActiveDirectorySchemaProperty newProperty =
                new ActiveDirectorySchemaProperty(
                    context,
                    newPropertyLdapDisplayName);

            // set the properties for this schema class
            newProperty.CommonName     = newPropertyCommonName;
            newProperty.Oid            = newPropertyOid;
            newProperty.IsSingleValued = true;
            newProperty.Syntax         = newPropertySyntax;
            // replicated to global catalog
            newProperty.IsInGlobalCatalog = true;

            // save the new class to the backend store
            try
            {
                newProperty.Save();
            }
            catch (ActiveDirectoryObjectExistsException)
            {
                // a class by this name already exists
                Console.WriteLine("FAILED to created new property.");
                return;
            }
            Console.WriteLine("Property \"{0}\" created successfully.",
                              newPropertyLdapDisplayName);
        }
Exemple #2
0
        // You can use the DirectoryServer or Forest value of the DirectoryContextType enumeration
        // for connecting to and then extending an AD schema.
        // However, use caution when extended an AD schema. Additions are not easily reversible


        public static void CreateNewAttribute()
        {
            //specify a common name
            string newAttributeCommonName = "New-Attribute1";

            //specify an OID value. The root name was generated by oidgen.exe
            string newAttributeOid =
                "1.2.840.113556.1.4.7000.233.28688.28684.8.145234.1728134.2034934.1932637.1";

            // specify a syntax
            ActiveDirectorySyntax syntax = ActiveDirectorySyntax.CaseIgnoreString;

            // create a new attribute schema object
            ActiveDirectorySchemaProperty newAttribute =
                new ActiveDirectorySchemaProperty(
                    adamContext,
                    newAttributeLdapDisplayName);

            // set attributes for this schema attribute object
            newAttribute.CommonName     = newAttributeCommonName;
            newAttribute.Oid            = newAttributeOid;
            newAttribute.IsSingleValued = true;
            newAttribute.Syntax         = syntax;

            // do not replicate to the global catalog
            // the default for isMemberOfPartialAttributeSet is already False, but this
            // setting is irrelevant for an ADAM instance.
            // newAttribute.IsInGlobalCatalog = false;

            try
            {
                // save the new attribute schema object to the schema
                newAttribute.Save();
            }
            catch (ActiveDirectoryObjectExistsException e)
            {
                // an object by this name already exists in the schema
                Console.WriteLine("The schema object \"{0}\" was not created. {1}",
                                  newAttributeLdapDisplayName, e.Message);
                return;
            }

            catch (ActiveDirectoryOperationException e)
            {
                // a call to the underlying directory was rejected
                Console.WriteLine("The schema object \"{0}\" was not created. {0}",
                                  newAttributeLdapDisplayName, e.Message);
                return;
            }

            Console.WriteLine("Attribute schema object \"{0}\" created successfully.",
                              newAttributeLdapDisplayName);
        }