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)
}

Leave a Reply

Your email address will not be published. Required fields are marked *