I'm sure this is fairly basic but I can't seem to wrap my head around it and at this point it would almost be more prudent for me to do it manually but it seems like a good learning opportunity.
I created a custom attribute in AD. The users all have it set as an email to sync through a third party app, not associated with Active Directory. I need to change the domain name on all of them through Powershell from [email protected] to [email protected]. It seems easy enough but for some reason I can't get the Set-ADUser to change the property for each user and replace based off of the original username. I need to remove the last 27 characters of the old domain name, concatenate the current logon name with the new domain name, and then set it. It seems so simple yet I keep getting invalid arguments no matter how I try it in Powershell.
So far I have something like:
$Users = Get-ADUser -Filter "*" -SearchBase 'OU=test,DC=adDomain,DC=org' -Properties customattribute
ForEach-Object {
$fullAttribute = Get-ADUser $_{customattribute}
$logon -replace "fullAttribute.{27}$"
$newLogon = $logon + "newdomainname.com"
Set-ADUser $_ -replace @{customattribute=$newLogon}
}
I keep trying to take it in stages but I keep running into syntax errors.
$fullAttribute = Get-ADUser $_{customattribute}
is supposed to do. Where is the$logon
variable being set? It isn't set to anything in your fragment.