How To: Access the Schema
The following classes are used with the Active Directory Domain Services schema.
- ActiveDirectorySchema
- ActiveDirectorySchemaClass
- ActiveDirectorySchemaClassCollection
- ActiveDirectorySchemaProperty
- ActiveDirectorySchemaPropertyCollection
The GetCurrentSchema static method can be used to obtain the ActiveDirectorySchema object that represents the schema for the forest that the currently logged-on user is a member of.
The following examples demonstrate how to use the System.DirectoryServices.ActiveDirectory namespace to work with the Active Directory Domain Services schema.
Enumerating Schema Classes
The following C# example shows how to enumerate all of the classes in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumSchemaClasses(ActiveDirectorySchema schema)
{
foreach (ActiveDirectorySchemaClass schemaClass in
schema.FindAllClasses())
{
Console.WriteLine(schemaClass.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all of the classes in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumSchemaClasses(ByVal schema As ActiveDirectorySchema)
Dim schemaClass As ActiveDirectorySchemaClass
For Each schemaClass In schema.FindAllClasses()
Console.WriteLine(schemaClass.Name)
Next schemaClass
End Sub 'EnumSchemaClasses
The following C# example shows how to enumerate all classes of the specified type in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumSchemaClasses(ActiveDirectorySchema schema,
SchemaClassType classType)
{
foreach (ActiveDirectorySchemaClass schemaClass in
schema.FindAllClasses(classType))
{
Console.WriteLine(schemaClass.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all classes of the specified type in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumSchemaClasses(ByVal schema As ActiveDirectorySchema, _
ByVal classType As SchemaClassType)
Dim schemaClass As ActiveDirectorySchemaClass
For Each schemaClass In schema.FindAllClasses(classType)
Console.WriteLine(schemaClass.Name)
Next schemaClass
End Sub 'EnumSchemaClasses
The following C# example shows how to enumerate all defunct classes in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumDefunctSchemaClasses(ActiveDirectorySchema schema)
{
foreach (ActiveDirectorySchemaClass schemaClass in
schema.FindAllDefunctClasses())
{
Console.WriteLine(schemaClass.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all defunct classes in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumDefunctSchemaClasses(ByVal schema As ActiveDirectorySchema)
Dim schemaClass As ActiveDirectorySchemaClass
For Each schemaClass In schema.FindAllDefunctClasses()
Console.WriteLine(schemaClass.Name)
Next schemaClass
End Sub 'EnumDefunctSchemaClasses
Enumerating Schema Properties
The following C# example shows how to enumerate all of the properties in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumSchemaProperties(ActiveDirectorySchema schema)
{
foreach (ActiveDirectorySchemaProperty schemaProperty in
schema.FindAllProperties())
{
Console.WriteLine(schemaProperty.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all of the properties in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumSchemaProperties(ByVal schema As ActiveDirectorySchema)
Dim schemaProperty As ActiveDirectorySchemaProperty
For Each schemaProperty In schema.FindAllProperties()
Console.WriteLine(schemaProperty.Name)
Next schemaProperty
End Sub 'EnumSchemaProperties
The following C# example shows how to enumerate all of the properties of a specific type in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumSchemaProperties(ActiveDirectorySchema schema,
PropertyTypes propertyType)
{
foreach (ActiveDirectorySchemaProperty schemaProperty in
schema.FindAllProperties(propertyType))
{
Console.WriteLine(schemaProperty.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all of the properties of a specific type in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumSchemaProperties(ByVal schema As ActiveDirectorySchema, _
ByVal propertyType As PropertyTypes)
Dim schemaProperty As ActiveDirectorySchemaProperty
For Each schemaProperty In schema.FindAllProperties(propertyType)
Console.WriteLine(schemaProperty.Name)
Next schemaProperty
End Sub 'EnumSchemaProperties
The following C# example shows how to enumerate all defunct properties in a specified schema.
using System.DirectoryServices.ActiveDirectory;
static void EnumDefunctSchemaProperties(ActiveDirectorySchema schema)
{
foreach (ActiveDirectorySchemaProperty schemaProperty in
schema.FindAllDefunctProperties())
{
Console.WriteLine(schemaProperty.Name);
}
}
The following Visual Basic .NET example shows how to enumerate all defunct properties in a specified schema.
Imports System.DirectoryServices.ActiveDirectory
Sub EnumDefunctSchemaProperties(ByVal schema As ActiveDirectorySchema)
Dim schemaProperty As ActiveDirectorySchemaProperty
For Each schemaProperty In schema.FindAllDefunctProperties()
Console.WriteLine(schemaProperty.Name)
Next schemaProperty
End Sub 'EnumDefunctSchemaProperties
Send comments about this topic to Microsoft.
Copyright © 2008 by Microsoft Corporation. All rights reserved.