# Set the backup folder path $backupFolder = "C:\ADBackup" # Set the folder name and the date format $backupFileName = "ADBackup_$(Get-Date -Format yyyy-MM-dd-HH-mm)" # Set the path for the backup file $backupFilePath = Join-Path $backupFolder $backupFileName # Create a backup of the Active Directory ntdsutil.exe "activate instance ntds" "ifm" "create full $backupFilePath" "quit" "quit" # Compress the backup file $zipFileName = $backupFileName + ".zip" $zipFilePath = Join-Path $backupFolder $zipFileName Compress-Archive -Path $backupFilePath -DestinationPath $zipFilePath -CompressionLevel Optimal # Delete the org. Folder Remove-Item -Path $backupFilePath -Recurse