We have users coming in from other OU. I am creating a script to copy all the necessary attributes in AD. All is okay, except for the homedirectory. The homedirectories are not always on the same server and not always in the same path. So I want to get the homedirectory in AD from the mirror user and replace the username with the incoming user.
\Server1\Users$\username1 (Mirror) to change to \Server1\Users$\username2 ($Incoming)
I created something like this, but it does not do the trick.
#Get usernames of incoming and mirror user
$Incoming = Read-Host -Prompt "Username incoming user"
$Mirror = Read-Host -Prompt "Username mirror user"
#Get Homedir and rename to Homedir Incoming user
$Homedir = Get-ADUser $Mirror -properties Homedirectory |Select-Object -ExpandProperty Homedirectory
$NewHomeDir = $Homedir-Replace('$Mirror', '$Incoming')
I must be overlooking something, but what?