Roll back UPN Script

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 
##########################################################################

Regards

Sukhija Vikas

http://msexchange.me

Posted in Office 365 | Tagged , | Leave a comment

Office 365 Users Service Usage Report

Lately working on office 365 exchange online, federation & other stuff so created this script for checking the Service usage across users.

This script is still evolving but does a prety good job on services part, below is the sample result that is available after script is executed.

 

Prerequisites:

Install Microsoft Online Services Sign-In Assistant for IT Professionals 32 bit/64 bit both are available when you will browse the link.

Install Microsoft Online Services Module for Windows PowerShell 32 bit/64 bit both are available when you will browse the link.

Refer:

Connecting Office 365 via PowerShell

Ones you are setup, connect to Connect-MsolService, enter your office 365 admin  credentials.

Change directory in the shell to where you have kept this downloaded script. (download from below link)

https://gallery.technet.microsoft.com/scriptcenter/Office-365-Users-Service-dcbd618b

type .\Get-Office365UsersServiceUasgeReportv1 & press enter to execute.

Script will start processing the results in csv file.

 

Resulting CSV will be in same folder:

Let me know if you want to add more information in the report.

############################################################### 
#            Author: Vikas Sukhija (http://msexchange.me) 
#            Date: 8/4/2016 
#            Reviewer: 
#            updated: 8/11/2016 (created heders/CSV logic) 
#            Updated: 8/15/2016 (fixed service status when m,ultiple licenses are there) 
#            Description: Office 365 users Report 
# 
############################################################### 
 
$collection = @() 
 
$output = new-item .\office365report.csv -type file -force 
 
$lict = Get-MsolAccountSku 
$services = $lict.ServiceStatus 
 
$csv = @() 
$csv1=$null 
 
foreach($service in $services){ 
$provisionstatus = $service.ProvisioningStatus 
$servicename = $service.ServicePlan.ServiceName 
$csv +$servicename} 
 
$expcsv=$csv | sort -Unique 
 
$countcs$expcsv.count 
 
foreach($cs in $expcsv){$csv1 += [string]$cs + ","} 
 
$csv2 = $csv1.Substring(0,$csv1.Length-1) 
 
add-content $output "FirstName,LastName,ImmutableId,SignInName,UserPrincipalName,License,$csv2" 
 
##################GEt values from users##################### 
 
$allusers = get-msoluser -all 
 
foreach($user in $allusers){ 
 
$FirstName = $user.FirstName 
$LastName = $user.LastName 
$signInname = $user.SignInName 
$UserPrincipalName = $user.UserPrincipalName 
 
Write-host "Processing..................$UserPrincipalName" -foregroundcolor green 
 
$ImmutableId=$user.ImmutableId 
$licenses = $user.Licenses.AccountSkuId 
$license=$null 
if($licenses -notlike $null){ 
foreach($lic in $licenses){$license +$lic + ","$license$license.Substring(0,$license.Length-1)} 
 
$serviceplan = $user.Licenses.ServiceStatus.serviceplan 
$provsts = $user.Licenses.ServiceStatus.provisioningstatus 
$spcount = $serviceplan.count 
 
[int]$spcount1=$spcount -1 
[int]$countcs1=$countcs -1 
 
################Compare the Header with Values################ 
 
$provval1=@(0..[int]$countcs1for($j=0;$j -le [int]$countcs1;$j++){$provval1[$j]="not found"} 
 
 
for($i=0;$i -le [int]$spcount1;$i++){ 
    for($j=0;$j -le [int]$countcs1;$j++){ 
    if($serviceplan[$i].serviceName -eq $expcsv[$j]){ 
    $provval1[$j] = [string]$provsts[$i]} } 
} 
 
$prov=$null 
for($j=0;$j -le [int]$countcs1;$j++){ 
$prov += [string]$provval1[$j+ ","} 
 
$prov1$prov.Substring(0,$prov.Length-1) 
 
#####################License values####################################### 
 
switch -Wildcard ($license){ 
    "*DESKLESSPACK*" {$licensevalue="Office 365 (Plan K1)"}  
        "*DESKLESSWOFFPACK*" {$licensevalue="Office 365 (Plan K2)"}  
        "*LITEPACK*" {$licensevalue="Office 365 (Plan P1)"}  
        "*EXCHANGESTANDARD*" {$licensevalue="Office 365 Exchange Online Only"}  
        "*STANDARDPACK*" {$licensevalue="Office 365 (Plan E1)"}  
        "*ENTERPRISEPACK*" {$licensevalue="Office 365 (Plan E3)"}  
        "*ENTERPRISEPACKLRG*" {$licensevalue="Office 365 (Plan E3)"} 
        "*ENTERPRISEWITHSCAL*" {$licensevalue="Office 365 (Plan E4)"} 
        "*STANDARDPACK_STUDENT*" {$licensevalue="Office 365 (Plan A1) for Students"} 
    "*ENTERPRISEPACK_STUDENT*" {$licensevalue="Office 365 (Plan A3) for Students"} 
    "*ENTERPRISEWITHSCAL_STUDENT*" {$licensevalue="Office 365 (Plan A4) for Students"} 
    "*STANDARDPACK_FACULTY*" {$licensevalue="Office 365 (Plan A1) for Faculty"} 
    "*STANDARDWOFFPACKPACK_FACULTY*" {$licensevalue="Office 365 (Plan A2) for Faculty"} 
    "*ENTERPRISEPACK_FACULTY*" {$licensevalue="Office 365 (Plan A1) for Students"} 
    "*STANDARDPACK_STUDENT*" {$licensevalue="Office 365 (Plan A1) for Students"}     
    "*ENTERPRISEPACK_FACULTY*" {$licensevalue="Office 365 (Plan A3) for Faculty"} 
    "*ENTERPRISEWITHSCAL_FACULTY*"{$licensevalue="Office 365 (Plan A4) for Faculty"} 
    "*ENTERPRISEPACK_B_PILOT*" {$licensevalue="Office 365 (Enterprise Preview)"} 
    "*STANDARD_B_PILOT*" {$licensevalue="Office 365 (Small Business Preview)"} 
        default {$licensevalue="not found"} 
} 
 
add-content $output "$FirstName,$LastName,$ImmutableId,$signInname,$UserPrincipalName,$licensevalue,$prov1" 
 
 
} 
######################################
Regards
Sukhija Vikas
Posted in Office 365 | Tagged , , , | Leave a comment

How to Merge User accounts in Office 365 with on-premise User accounts

While working with one of the customer who was already using office 365 for office proplus services but was having all user ids for example as @lab.onmicrosoft.com.

Now they are ready for synchronization with their on premise infrastructure but don’t want duplicate ids to be created so here are the summary of steps that needs to be done so that user accounts are merged.

  • ADD a domain to office365 installation by following ADD domain wizard, example lab.com.

Go to office 365 admin console –> Settings –> Domains –> ADD Domain

Capture

This will ask you to create a TXT record in the DNS for lab.com

Name:@

Value: MS=code for authorization

TTL: 3600 or provider default

This record assists Microsoft to check the authorization of the domain, this will not change any of the services that are already running in the environment so just create it.

Note: First You have to change the on-premise users UPN to Primary SMTP address, before synchronization of Active Directory to the cloud.

Ones the domain is added you need to change the UPN of Cloud user to match the UPN of on-premise user i.e. Primary SMTP address.

As UPN matches on both locations  so ones you synchronize AD by using Azure AD connect  display Sync Type will change from In cloud  to synced with Active directory as shown below.

Capture

Regards

Sukhija Vikas

http://msexchange.me

 

Posted in Active Directory, Office 365 | Tagged , , | Leave a comment

Skip DNS registration for Particular IP Addresses

Today I am sharing a TIP which can be used to skip DNS registration of some of the IP addresses (when you have assigned multiple IP to a single NIC).

When NIC’s are multiple , its easy to just uncheck the box for DNS registration as shown below:(register this connection’s address in DNS )

Capture

Challenge comes when you have a Single NIC & multiple addresses:)

So here is the TIP which utilizes cool Netsh,

ADD the first IP address to the NIC that you want to register in DNS.

Other IP addresses that you need to ADD to NIC , use following commands

Netsh Int IPv4 Add Address NIC1 10.X.X.1 SkipAsSource=True
Netsh Int IPv4 Add Address NIC1 10.X.X.2 SkipAsSource=True

NIC1 is name of the adaptor, you need to note it before hand.

Capture

Now these IP addresses will not get register in DNS.

This article is applicable to windows 2008 & above.

Regards

Sukhija Vikas

http://msexchange.me

 

Posted in SystemAdmin | Tagged , | Leave a comment

Fix Office 365 UPN

Today I am sharing a script that We have written to fix office 365 UPN.

This can help the organizations moving to office 365 & want to update the UPN in phases rather than big bang approach.

Prerequisites: Exchange management Shell

Extract the script from below link & update the text file with samaccountnames of the users for whom you want to match the UPN with SMTP address.

https://gallery.technet.microsoft.com/scriptcenter/Fix-Office-365-UPN-abb1a62f

Run the batch file, script will log as well as report in respective folders.

Report will be as below:

######################################################################### 
#            Author: Vikas Sukhija 
#            Reviewer: 
#            date: 7/6/2016 
#            Modified:7/11/2016                         
#            Description: Fix o365 UPN 
#            Update: Added reporting 
######################################################################### 
 
$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" 
 
$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 
} 
 
 
$users = get-content .\users.txt 
 
$users | foreach-object{ 
 
$user = $_ 
 
$mbx=Get-User $user | Where { -Not [string]::IsNullOrEmpty($_.WindowsEmailAddress) }  
 
$mbcoll = "" | select Name,ExistingUPN,WindowsEmailAddress,ModifiedUPN 
 
if($mbx){ 
 
    if($mbx.UserPrincipalName -eq $mbx.WindowsEmailAddress) { 
 
    Write-host "$user is already setup as "$mbx.UserPrincipalName"" -foregroundcolor blue  
    $mbcoll.Name = $mbx.Name 
    $mbcoll.ExistingUPN = $mbx.UserPrincipalName 
    $mbcoll.WindowsEmailAddress = $mbx.WindowsEmailAddress 
    $mbcoll.ModifiedUPN = "Not Modified" } 
 
    else{ 
 
    Set-User -identity $mbx -UserPrincipalName $mbx.WindowsEmailAddress.ToString() 
    Write-host "Updating UPN for $user as "$mbx.WindowsEmailAddress"" -foregroundcolor green 
    #For($i = 1; $i -le "5"; $i++){ sleep 1;Write-Progress -Activity "Updating UPN for $user" -status "$i" -percentComplete ($i /10*100)} 
    #$mbx1 = get-user -identity $mbx 
    $mbcoll.Name = $mbx.Name 
    $mbcoll.ExistingUPN = $mbx.UserPrincipalName 
    $mbcoll.WindowsEmailAddress = $mbx.WindowsEmailAddress 
    $mbcoll.ModifiedUPN = $mbx.WindowsEmailAddress } 
        } 
 
else{ 
 
$mbx=Get-User $user 
write-host "$user ..doesn't have ..WindowsEmailAddress" -foregroundcolor magenta 
    $mbcoll.Name = $mbx.Name 
    $mbcoll.ExistingUPN = $mbx.UserPrincipalName 
    $mbcoll.WindowsEmailAddress = $mbx.WindowsEmailAddress 
    $mbcoll.ModifiedUPN = "Empty Windows Email"$collection +$mbcoll 
} 
 
$collection | export-csv $report -notypeinfo 
 
stop-transcript 
####################################################################

Regards

Sukhija Vikas

http://msexchange.me

Posted in Active Directory, Office 365, Scripting | Tagged , , | Leave a comment

Mailbox Move Agent

Sharing a script that I named as Mailbox agent, it is a package of 3 scripts:

1-SubmitMailBoxMoveRequests.ps1

2-ResumeMailBoxMove.ps1

3-ClearCompleteMailBoxMove.ps1

These we used during mailbox moves from old dags to newly created dags for exchange 2010.

update 1-SubmitMailBoxMoveRequests.ps1 script with OLDDAG/NewDAG name

$mbxsrvsrc = “OLDdag01”

$mbxsrvdst = “Newdag01”

Script will check the $countperday value & from each databse migrate the number of  malboxes (based on the value) to all destination databases.

Example: If DAGOLD has 4 databases & value for $countperday = 10

than 10 mailboxes from each DB will be migrated to destination databses.

if DAGNEW has 10 databases than 1 mailbox will be moved to db1, 2nd will move to db2 & soon…

Mailboxes will be equally distributed among all destination DBs. (this will be all automatic)

1-SubmitMailBoxMoveRequests.ps1  –> This will submit the requests & suspends after 95% completion

2-ResumeMailBoxMove.ps1 –> This will resume the request based on geography if required, just update the $region.

example: $region = “United Kingdom” (keep its value as * if you don’t want to use region)

3-ClearCompleteMailBoxMove.ps1 –> This will clear the completed requests.

All these scripts will send report in email, so please update the email variables inside the scripts.

$smtpserver = 

$from = 

$email1 = 

Extract the scripts from below link, hopefully these will work for you & will make mailbox moves easy.

https://gallery.technet.microsoft.com/scriptcenter/Mailbox-Move-Agent-08921668

 

you can also filter out the mailboxes that you want to move by updating the submit script, below is the example:

that I used to avoid migration of certain mailboxes & also just migrate the ones above 10 MB quota.

$mbx += get-mailbox -database $db -resultsize $countperday | where{(($_.MailboxMoveStatus -like “None”) -and ($_.Name -notlike “sys*”) -and ($_.ProhibitSendQuota -gt “10 MB”))}

 

 

Regards

Sukhija Vikas

http://msexchange.me

Posted in Exchange, Scripting | Tagged , , , , | Leave a comment