A belt-and-suspenders Active Directory safety backup script designed to run immediately before a risky change (schema update, bulk object edit, GPO overhaul, DC promotion/demotion, etc.). It is independent of your primary backup product (Veeam, Commvault, etc.) and produces portable, standalone artifacts you can restore from without any third-party tooling.
Hypervisor snapshots and even application-aware VM backups can fail silently, get blocked by EDR (looking at you, SentinelOne boot protection), or simply not be granular enough when all you need to do is roll back one OU or one GPO. This script gives you a self-contained directory of everything you'd want to diff against or restore from after a bad change, in formats every AD admin already knows how to use.
Under <BackupRoot>\<timestamp>\:
| Artifact | Description | Restore tool |
|---|---|---|
IFM\ |
Full ntds.dit + SYSVOL via ntdsutil ifm create full |
Promote a fresh DC from media, or mount offline with dsamain |
GPOs\ |
Every GPO backed up via Backup-Gpo -All |
Restore-Gpo |
ADObjects\users.xml |
All users with all properties | Import-Clixml + Set-ADUser |
ADObjects\groups.xml |
All groups with all properties | Import-Clixml + Set-ADGroup |
ADObjects\group-membership.xml |
Flat group→members map for every group | Add-ADGroupMember in a loop |
ADObjects\computers.xml |
All computer objects | Import-Clixml |
ADObjects\ous.xml |
All OUs with all properties | Import-Clixml |
fsmo-roles.txt |
Output of netdom query fsmo |
Reference |
recyclebin-status.txt |
ENABLED or DISABLED |
Reference |
backup.log |
Timestamped run log | Reference |
ntdsutil.log |
Raw ntdsutil output | Reference |
manifest-sha256.txt |
Integrity manifest for all backup files | Verify-ADBackupManifest.ps1 |
- Integrity manifest: Script now generates
manifest-sha256.txtfor every run. - Fail-closed mode: Use
-FailOnCriticalStepto terminate if critical backup stages fail. - Scoped exports: Use
-ExportMode Scoped -SearchBase <DN>to reduce data collection and runtime. - Optional IFM skip: Use
-SkipIFMfor non-DC dry runs or object/GPO-only snapshots. - Attribute allowlists: Object backup defaults to selected attributes (not all properties), reducing sensitive over-collection by default.
Restore-ADObjectsFromBackup.ps1: Object-level restore helper with-WhatIfsupport and allowlisted attributes.Verify-ADBackupManifest.ps1: Verifies file integrity againstmanifest-sha256.txt.
- Domain-joined Windows host with:
- PowerShell 5.1+ (or PowerShell 7)
ActiveDirectorymodule (RSAT-AD-Tools)GroupPolicymodule (GPMC)
- Domain Admin (or equivalent) credentials
- The IFM step must run on an actual domain controller —
ntdsutil ifmonly works on a DC. If you run the script from a management box, every other step works but IFM is skipped with a warning. - Enough free disk at
-BackupRootfor a full copy ofntds.dit+ SYSVOL (plan for the size of your NTDS volume on any DC).
Clone or copy the script to the target DC:
# Default - writes to C:\ADBackup\<timestamp>\
.\Backup-ADPreChange.ps1
# Custom location (file share, another drive, etc.)
.\Backup-ADPreChange.ps1 -BackupRoot "D:\ADBackup"
.\Backup-ADPreChange.ps1 -BackupRoot "E:\ADBackup"Run as Administrator in a PowerShell session opened by a Domain Admin account.
Best practice: run on the PDC Emulator. Find it with:
(Get-ADDomain).PDCEmulator-
ntdsutil ifmmay refuse to write directly to certain mapped drives or UNC paths depending on session context. If the IFM step fails on a network path but everything else succeeds, re-run with a local path (C:\ADBackup) and copy the output folder to your final destination afterward:Copy-Item C:\ADBackup\20260414-* \\fileserver\backups\AD\ -Recurse
Copy the backup folder off the DC. A backup sitting on the C: drive of the machine it's backing up is not a backup.
Copy-Item 'C:\ADBackup\20260414-160530' '\\fileserver\backups\AD\' -RecurseKeep these handy in your change runbook.
Restore-Gpo -Name "Some Policy" -Path "C:\ADBackup\<timestamp>\GPOs"Restore-Gpo -All -Path "C:\ADBackup\<timestamp>\GPOs"$before = Import-Clixml "C:\ADBackup\<ts>\ADObjects\users.xml"
$after = Get-ADUser -Filter * -Properties *
Compare-Object $before $after -Property SamAccountName, Enabled, MemberOfGet-ADObject -Filter 'IsDeleted -eq $true -and Name -like "*username*"' -IncludeDeletedObjects |
Restore-ADObjectOn a freshly installed Windows Server that will become the recovery DC:
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
Install-ADDSDomainController `
-DomainName "corp.example" `
-InstallDns `
-InstallationMediaPath "C:\IFM" `
-Credential (Get-Credential)Copy the contents of the IFM\ folder from the backup to C:\IFM on the new server first.
-
It does not replace your enterprise backup product. Run it in addition to Veeam/Commvault/etc., not instead of.
-
It does not back up certificate services, DHCP, DNS zones stored outside AD, or any non-AD server role. Those need their own backup procedures.
-
It does not back up AD-integrated DNS records separately — they live in
ntds.ditand come along with the IFM. If you need granular DNS record restore, export zones separately withExport-DnsServerZone. -
It does not enable AD Recycle Bin. It checks and warns. Enable it manually (one-way operation) before your change:
Enable-ADOptionalFeature 'Recycle Bin Feature' ` -Scope ForestOrConfigurationSet ` -Target (Get-ADForest).RootDomain
- Verify AD Recycle Bin is enabled.
- Run this script; confirm all five steps succeed.
- Copy the output folder off the DC to a separate host.
- Take your normal Veeam (or equivalent) backup with app-aware processing.
- Document current FSMO role holders and any objects you plan to modify.
- Perform the change.
- Diff against
users.xml/groups.xml/ous.xmlto confirm only intended objects changed. - Keep the backup for at least one tombstone lifetime (default 180 days) before deleting.
# Dry-run user and group attribute restore
.\Restore-ADObjectsFromBackup.ps1 -BackupPath "C:\ADBackup\<timestamp>" -RestoreUsers -RestoreGroups -WhatIf
# Apply group membership restoration only
.\Restore-ADObjectsFromBackup.ps1 -BackupPath "C:\ADBackup\<timestamp>" -RestoreGroupMembership.\Verify-ADBackupManifest.ps1 -BackupPath "C:\ADBackup\<timestamp>"MIT. Use at your own risk. Test in a lab first. The author is not responsible for domains that get bricked by untested changes, including ones this script was supposed to help roll back from.