Exemplo n.º 1
0
        public static void CreateNewClass()
        {
            // create a new class object
            ActiveDirectorySchemaClass newClass =
                new ActiveDirectorySchemaClass(
                    context,
                    newClassLdapDisplayName);

            // set the properties for this schema class
            newClass.CommonName = newClassCommonName;
            newClass.Oid        = newClassOid;
            newClass.SubClassOf = ActiveDirectorySchemaClass.FindByName(
                context,
                newClassSubClassOf);
            newClass.Type = SchemaClassType.Structural;
            // adding the previously created property as an optional property
            newClass.OptionalProperties.Add(
                ActiveDirectorySchemaProperty.FindByName(
                    context,
                    newClassOptionalProperty));

            // save the new class to the backend store
            try
            {
                newClass.Save();
            }
            catch (ActiveDirectoryObjectExistsException)
            {
                // a class by this name already exists
                Console.WriteLine("FAILED to created new class.");
                return;
            }
            Console.WriteLine("Class \"{0}\" created successfully.",
                              newClassLdapDisplayName);
        }
Exemplo n.º 2
0
        public static void CreateNewClass()
        {
            // specify a common name
            string newClassCommonName = "new-Class";

            // specify an lDAPDisplayName
            string newClassLdapDisplayName = "newClass";

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

            string subClassOf = "top";

            string possibleSuperior = "organizationalUnit";

            // add an optional attribute to the new schema class object
            // This example adds the new attribute created in the CreateNewAttribute method
            string newClassOptionalAttribute = newAttributeLdapDisplayName;


            // create a new class object
            ActiveDirectorySchemaClass newClass =
                new ActiveDirectorySchemaClass(
                    adamContext,
                    newClassLdapDisplayName);

            // set the attribute values for this schema class object
            newClass.CommonName = newClassCommonName;
            newClass.Oid        = newClassOid;

            newClass.Type = SchemaClassType.Structural;

            // assign the parent class
            newClass.SubClassOf = ActiveDirectorySchemaClass.FindByName(adamContext,
                                                                        subClassOf);

            // add the previously created attribute as an optional attribute
            newClass.OptionalProperties.Add(
                ActiveDirectorySchemaProperty.FindByName(adamContext,
                                                         newClassOptionalAttribute));

            //add an OU as a possible superior so that this class can be
            //instantiated in an OU
            newClass.PossibleSuperiors.Add(
                ActiveDirectorySchemaClass.FindByName(adamContext,
                                                      possibleSuperior));

            // save the new class to the schema
            try
            {
                newClass.Save();
            }

            catch (ActiveDirectoryObjectExistsException e)
            {
                // an schema object by this name already exists in the schema
                Console.WriteLine("The schema object {0} was not created. {0}",
                                  newClassLdapDisplayName, e.Message);
                return;
            }

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

            Console.WriteLine("Class \"{0}\" created successfully.",
                              newClassLdapDisplayName);
        }
Exemplo n.º 3
0
        private static void createSchemaClass(object domainDCs)
        {
            try
            {
                if (!DirectoryEntry.Exists("LDAP://CN=nmlsNetworkDriveClass,cn=Schema,cn=Configuration," + domainDCs))
                {
                    DirectoryContext ctx = new DirectoryContext(DirectoryContextType.Forest);

                    ActiveDirectorySchemaClass schemaClass = new ActiveDirectorySchemaClass(ctx, "nmlsNetworkDriveClass");
                    schemaClass.Oid        = "1.2.840.113556.1.8000.2554.61823.22188.26389.18272.44952.1599828.8363415.3.1";
                    schemaClass.SubClassOf = new ActiveDirectorySchemaClass(ctx, "top");
                    schemaClass.OptionalProperties.AddRange(new ActiveDirectorySchemaProperty[] {
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveA"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveB"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveC"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveD"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveE"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveF"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveG"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveH"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveI"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveJ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveK"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveL"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveM"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveN"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveO"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveP"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveQ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveR"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveS"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveT"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveU"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveV"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveW"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveX"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveY"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveZ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelA"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelB"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelC"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelD"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelE"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelF"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelG"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelH"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelI"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelJ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelK"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelL"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelM"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelN"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelO"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelP"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelQ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelR"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelS"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelT"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelU"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelV"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelW"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelX"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelY"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelZ")
                    });

                    schemaClass.Type = System.DirectoryServices.ActiveDirectory.SchemaClassType.Auxiliary;

                    schemaClass.Save();

                    //schemaClass
                }
                else
                {
                    Console.WriteLine("Class already exists");
                }

                DirectoryEntry userClass = new DirectoryEntry("LDAP://cn=User,cn=Schema,cn=Configuration," + domainDCs);

                if (!userClass.Properties["auxiliaryClass"].Contains("nmlsNetworkDriveClass"))
                {
                    userClass.Properties["auxiliaryClass"].Add("nmlsNetworkDriveClass");
                    userClass.CommitChanges();
                }
                else
                {
                    Console.WriteLine("User class already has auxiliary class nmlsNetworkDriveClass");
                }


                // Add NMLS class also OU objects.

                DirectoryEntry ouClass = new DirectoryEntry("LDAP://cn=Organizational-Unit,cn=Schema,cn=Configuration," + domainDCs);
                if (!ouClass.Properties["auxiliaryClass"].Contains("nmlsNetworkDriveClass"))
                {
                    ouClass.Properties["auxiliaryClass"].Add("nmlsNetworkDriveClass");
                    ouClass.CommitChanges();
                }
                else
                {
                    Console.WriteLine("OU class already has auxiliary class nmlsNetworkDriveClass");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }