I'm trying to replicate users with Path OU which is structured the same and I replaced the parent OU and the domain only. But I'm getting an error. Please see the script below and the error.
Domain B users // Domain with Trust
$Limausers = (Get-ADUser -Server "$SeverB" -Credential $credential -filter "displayname -like 'sp *'" -searchbaseB $searchbase -properties *)
Target path
$targetpath= foreach ($Lima in $Limausers) {
$LimaString= $Lima -replace '^.+?(?<!\),',''
$path = Out-String -inputobject $LimaString
$path.replace("Lima","NBAinc") -replace ("net","org") -replace ("Test OU","Test")
}
$targetpath
Domain A users // My domain
$searchbase = "OU=Test mig, OU=Test, DC=NBAinc, DC=org"
$NBAUsers = (Get-ADUser -server $serverA -Filter * -searchbase $searchbaseA -properties *)
$NBAusers.displayname
Loop
foreach($NBA in $NBAusers) {
if ($Limausers.displayname -eq $NBA.displayname) {
$userdisplayname= (Get-ADUser -Filter "displayname -eq '$($displayname)'" -properties *).distinguishedname
Move-ADObject -Identity $NBA.DistinguishedName -TargetPath $targetpath }
}
Error:
Move-ADObject : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'TargetPath'. Specified method is not
supported.
At C:\Temp\MigrationTestScript.ps1:38 char:62