Код:
Get-ADComputer -Filter "extensionAttribute1 -like '*'" -Properties extensionAttribute1,extensionAttribute2 | Group-Object extensionAttribute1 | Foreach {
$ex2 = $_.Group | Where {$_.extensionAttribute2 -match "^\d{3}$"} | Foreach-Object {$_.extensionAttribute2}
$start = 0
$id = "$start".PadLeft(3,'0')
$_.Group | Where {$_.extensionAttribute2 -notmatch "^\d{3}$"} | Foreach-Object {
do {
$start++
$id = "$start".PadLeft(3,'0')
} while($ex2 -contains $id)
Set-ADComputer $_ -Replace @{extensionAttribute2=$id}
}
}