Office 365 UPN Update for MERGE

This is another addition to office 365 gallery, not complex but handy.

It can be used when you want to merge the user ids from cloud & onpremise.

Situation is that there are existing users in o365 & now you are ready to sync the directory thru AAD Connect.

Before running the syncronization you need to match the UPN of cloud users to UPN of onpremise accounts so that merge happenes.

Create a csv file:

Log on to MSOL from your machine.

Now change to the location of the script & exceute as below( where csv file is the file you created above)

Download the script Zip from below link or copy the code & create below structure before executing.

https://gallery.technet.microsoft.com/scriptcenter/Office-365-update-UPN-57b69981

 

 

PowerShell
############################################################### 
#            Author: Vikas Sukhija (http://msexchange.me) 
#            Date: 8/24/2016 
#            Reviewer: 
#            Decription: Change o365 UPN based on onpremise UPN 
# 
############################################################### 
 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/","-"$time = get-date -format t 
 
$time = $time.ToString().Replace(":""-"$time = $time.ToString().Replace(" """) 
 
$logs = ".\Logs" + "\" + "Processed_" + $date1 + "_" + $time + "_.log" 
$report = ".\report" + "\" + "Report_" + $date1 + "_" + $time + "_.csv" 
 
$pslogs = ".\Logs" + "\" + "Pslogs_" + $date1 + "_" + $time + "_.log" 
 
start-transcript $pslogs 
 
$data = import-csv $args[0]  
 
foreach($i in $data){ 
 
$CloudUPN = $i.cloudUPN 
$onpremUPN = $i.onpremUPN 
 
$date = get-date 
 
write-host "$date - $CloudUPN will be set to $onpremUPN" -foregroundcolor magenta 
add-content $logs "$date - $CloudUPN will be set to $onpremUPN" 
 
get-msoluser -UserPrincipalName $CloudUPN | Set-MsolUserPrincipalName -NewUserPrincipalName $onpremUPN 
 
if($error -ne $null){ Write-host "$onpremUPN ---- Processed" -foregroundcolor green 
 
add-content $logs "$onpremUPN ---- Processed" 
 
}  
else { 
 
Add-content $logs "$onpremUPN .....failed processing" -foregroundcolor yellow 
Write-host "$onpremUPN ---- Error Occured" -foregroundcolor yellow 
 
$error.clear 
} 
 
} 
 
stop-transcript 
################################################################

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s