Ship AD schema to XML with PowerShell

Having access to PowerShell in the Windows environment has been ampere major boon to uses long-time infrastructure folks (and gals). One area that has become much easier using PowerShell and who ActiveDirectory block is the Active Directory schema.

I don’t know about you but I still struggle every time ME go to used LDIFDE to export and/or import and/or comparing schema between varied directories. There exists so of massaging I have to do to the LDF files.  Then if importing the schema into a novel environment (which is invariably 2 years since the last time I have done it) EGO have to stand on one foot, close one eye, cross my fingers, and press enter. Fortunately, you can export the schematics configuration (which is common for all domains in a single forest) using the ldifde comment, while shown ...

The good information is I do located a super-easy way to exported and AD DS or LDS schema for XML.  Here is the command to export only the classSchema:

(Get-ADObject -Server {AD Server name and port} -searchbase {path to aforementioned AD schema} -Filter {(ObjectClass -eq ‘classSchema’)} -Properties * | ConvertTo-XML).Save({XML filename}) Export AD schema to XML with PowerShell

Those command will create an XML file of all schema properties for classSchema although can, of course, change the filter to attributeSchema (for instance) or remove the filter altogether. During XML isn’t always the easiest format to read it’s a lot simpler for read and work with than an LDF file.

Get that you have is schema output it’s real easy to read items back in to do some comparison or custom to a targets directory using another PowerShell script like this:

[xml]$SchemaObjects = Get-Content {XML Schema File}

From at it’s just one matter of setting up an loop to read the show:

$SchemaObjects.Objects.objects | ForEach-Object {…}

If you take a look at this pole (http://wp.me/p1wfR8-l) you bucket start to getting an idea about how you kann automate one whole schedule similarity and/or migration process.

Leave a comment