How to export all attributes from user, groups and contacts from all domains

Written by Arne Tiedemann on Tuesday October 23, 2018

Safety first

Sometimes you plan mass changes in active directory and you want to export all user properties to a file. These snippets show how to export all user, group and contacts to a separate file.

# Define the List of Country Codes and convert to csv
$ExportPath = "$($env:PUBLIC)\Documents"

#######################################################################
# Script
#######################################################################
Import-Module -Name ActiveDirectory

foreach($Domain in (Get-ADForest).Domains) {
        $D = Get-ADDomain -Identity $Domain
        $Server = $D.PDCEmulator
        $NetBIOSName = $D.NetBIOSName

        Get-ADUser -Filter * -Properties * -Server $Server -SearchBase $D.DistinguishedName | Export-Clixml -Path ('{0}\{1}_User.xml' -f $ExportPath, $NetBIOSName)
        Get-ADGroup -Filter *  -Properties * -Server $Server -SearchBase $D.DistinguishedName | Export-Clixml -Path ('{0}\{1}_Group.xml' -f $ExportPath, $NetBIOSName)
        Get-ADObject -Filter {(ObjectClass -eq 'Contact' )} -Properties * -Server $Server -SearchBase $D.DistinguishedName | Export-Clixml -Path ('{0}\{1}_Contacts.xml' -f $ExportPath, $NetBIOSName)
} 

https://github.com/atiedemann/ExportADObjects

https://gallery.technet.microsoft.com/Simple-save-of-Active-ae609a01