Jump to content

Recommended Posts

Posted
OK, so i have a new system to generate student accounts which has just thrown an issue. i have students with an initial in name and for some reason now have upn set correctly but primary email missing the initial. can anyone help me compare the two in AD and if they don't match set primary email to equal upn. i have found several scripts to do it the other way around but not as a comparison. We have O365 but sync from AD to cloud only, not two way. Just changing email attribute and primary smtp in proxy addresses works, but there are probably couple of hundred! Any help gratefully received.
Posted

This is written off the top of my head with no syntax checking, and I'm not at work to test.

 

$users = get-aduser -filter * -searchbase "ou=users,dc=domain,dc=local"
foreach ($user in $users){
$user = get-aduser $user -properties mail,upn
if ($user.upn -ne $user.mail){
set-aduser -identity  $user -mail $user.upn
}}

 

I think upn may be spelled out but this should give you an idea to get close to the goal.

 

Also I think wisesoft bulk adusers can use variables to do this as well.

  • Thanks 1
Posted

Thanks ADMaster.

With your start and few links finally got it sorted! Needed the primarySMTP address setting to the correct one too. This seems to work. Looks like 2 SMTP addresses in proxyaddresses but on sync to azure it takes the new one as primary.

 

$users = get-aduser -filter * -searchbase "OU=users,DC=domain,DC=local"foreach ($user in $users){$user = get-aduser $user -properties emailAddress,userPrincipalNameif ($user.userPrincipalName -ne $user.emailAddress){set-aduser -identity $user -emailAddress $user.userPrincipalNameset-ADUser $user -Add @{proxyAddresses = "SMTP:"+$user.userPrincipalName}}}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...