This is part 2 of Fix office 365 UPN script, Fix UPN Script can help organizations to fix the UPN in chunks
but if at anytime they feel the requirement to Rolback to the old UPN because something has broken
than this Rollback UPN script will assist.
Fix office 365 UPN Script:
https://gallery.technet.microsoft.com/scriptcenter/Fix-Office-365-UPN-abb1a62f
Download & extract the script zip from below link:
https://gallery.technet.microsoft.com/scriptcenter/Roll-back-UPN-Script-b1920fa1
Now just copy the report csv file that you want to rollback to old UPN from Fix office 365 UPN script & paste it inside the roll back script folder.
Now just execute the script in powershell as .\Fixo365upnRollback.ps1 Report_8-15-2016_9-22PM_.csv
All users inside the report will be rolled back to OLD UPN & new report will be placed inside report folder.
Note: Exchange management shell is requirement for running this script as well.
######################################################################### # Author: Vikas Sukhija # Reviewer: # date: 7/6/2016 # Modified:7/11/2016 # Description: Fix o365 UPN # Update: Added reporting # modified: Rollback capability based on csv ######################################################################### $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_Rollback" + $date1 + "_" + $time + "_.log" $report = ".\report" + "\" + "Report_Rollback" + $date1 + "_" + $time + "_.csv" $collection = @() Start-Transcript -Path $logs If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $data = import-csv $args[0] foreach($i in $data){ $user = $i.Name $rollbkupn = $i.ExistingUPN $winupn = $i.WindowsEmailAddress $mbx=Get-User $user $mbcoll = "" | select Name,ExistingUPN,WindowsEmailAddress,RollbackedUPN if($mbx){ if($mbx.UserPrincipalName -eq $winupn) { Set-User -identity $mbx -UserPrincipalName $rollbkupn Write-host "$user will be rolled back to $rollbkupn" -foregroundcolor blue $mbcoll.Name = $mbx.Name $mbcoll.ExistingUPN = $mbx.UserPrincipalName $mbcoll.WindowsEmailAddress = $mbx.WindowsEmailAddress $mbcoll.RollbackedUPN = $rollbkupn } else{ Write-host "$user UPN will not be modified" -foregroundcolor green $mbcoll.Name = $mbx.Name $mbcoll.ExistingUPN = $mbx.UserPrincipalName $mbcoll.WindowsEmailAddress = $mbx.WindowsEmailAddress $mbcoll.RollbackedUPN = "Not Rolledback" } } $collection += $mbcoll } $collection | export-csv $report -notypeinfo stop-transcript ##########################################################################
Tech Wizard