The script is to be run on the VBR itself which is not member of the domain. From the GUI the process works flawlessly - but on a user per user basis, which is not feasible for the large amount of users needed.
Code: Select all
# Get credentials to query live AD as VBR is not member of the domain
$cred = Get-Credential
# Connect to Veeam Backup Server
Connect-VBRServer -Server "localhost"
# Get the application-aware restore point for the VM on July 9, 2025
$appRestorePoint = Get-VBRApplicationRestorePoint | Where-Object {
$_.Name -eq "dc01.mydomain.local" -and
$_.CreationTime.Date -eq (Get-Date "2025-07-09").Date
}
# Start the AD restore session
$session = Start-VEADRestoreSession -RestorePoint $appRestorePoint[0]
# Get the backed-up domain
$domain = Get-VEADDomain -Session $session
# Get the container (OU)
$container = Get-VEADContainer -Domain $domain -Recurse | Where-Object {
$_.DistinguishedName -eq "OU=users,OU=company,DC=domain,DC=local"
}
# Get all user objects in the OU
$users = Get-VEADItem -Container $container | Where-Object { $_.Type -eq "user" }
foreach ($user in $users) {
# Get the backed-up manager attribute
$backupManager = $user.Attributes["manager"]
# Get the current manager from live AD
$liveUser = Get-ADUser -Identity $user.DistinguishedName -Properties manager -Server dc01.mydomain.local -Credential $cred
$liveManager = $liveUser.manager
# Compare and restore if different
if ($backupManager -ne $liveManager) {
Write-Host "Restoring manager for $($user.Name)...$($backupManager)->$($liveManager)"
Restore-VEADItem -Item $user -MergeAttributes
}
}
# End the session
Stop-VEADRestoreSession -Session $session
Code: Select all
$user.Attributes["manager"]
Also with
Code: Select all
Restore-VEADItem -Item $user -MergeAttributes
Any help much appreciated.
Thanks,
Mike