Hi Ilya,
You can do something like this.
#create a function that generates random letters
function getRandomLetters {
param (
[Parameter(Mandatory)][int]$amount,
[Parameter(Mandatory)][ValidateSet("Upper", "Lower", "Mixed")]$case
)
switch ($case) {
Upper { -join ((65..90) | Get-Random -Count $amount | ForEach-Object { [char]$_ }) }
Lower { -join ((97..122) | Get-Random -Count $amount | ForEach-Object { [char]$_ }) }
Mixed { -join ((65..90) + (97..122) | Get-Random -Count $amount | ForEach-Object { [char]$_ }) }
}
}
# Use it later to attach these letters to the conflicting value (like Common Name).
$newName = -join ($user.CN, "_", (getRandomLetters -amount 3 -case Lower))
Rename-ADObject -Identity $user.DistinguishedName -NewName $newName
# Move the object using the ObjectGUID, because the DN would have changed with the rename.
Move-ADObject -Identity $user.ObjectGUID -TargetPath $TargetOU
I hope it helps.