GoDaddy Office365 to Microsoft Office365 Migration- Part 7

Onboarding User Objects

During this phase, All user objects who are part of the migrations scope needs a corresponding user object on the target tenant. Since we have exported the user dump from GoDaddy tenant, User Objects can be created newly on the target tenant keeping the required attributes. However, few key attributes needs to be adjusted with the target enviornment.

For example, UPN in GoDaddy tenant which is currently used might be “YourDomain.com”. However, the same domain name cannot be made available on the target tenant at this stage. Hence, the approach we should take is to adjust the user principal name with the default onmicrosoft.com domain provided by Microsoft. UPN will be corrected on the cutover day and until we cross that time, the interim UPN can be used.

If users are having thumbnails, The exported files will be available in .\Thumbs folder. However, import may fail if the file size is above 100KB. In my experience, its better to keep the thumb size below 80KB to be on safer side.

Here is a sample script which can import AzureAD User Objects from the exported data. Note that user object in this context is only the actual users with a valid UPN pointing to the production domain. Guest users are not getting recreated through scripts, rather they need a new invite from the new tenant. While accepting the invite, New guest user account will get created. We will discuss that along with teams.

<# Update this section first #>
[string]$OnMicrosoftdomain = "youronmicrosoftdomain.onmicrosoft.com"
[string] $productiondomain = "*yourproductiondomain.com"
$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$PasswordProfile.Password = "y0uRP@ww0rd"


IF ((Test-Path -Path "C:\GoDaddyTenant\Export\AADUsers\AllUsers.CSV") -like "True")
    {
    [array] $AllUsers = Import-CSV "C:\GoDaddyTenant\Export\AADUsers\AllUsers.CSV"
    Connect-AzureAD
    $Len = $AllUsers.Count
    For ($i = 0; $i -lt $Len ; $i++)
        {
        IF ($AllUsers.UserType[$i] -eq "Member" -and $AllUsers.UserPrincipalName[$i] -match $productiondomain)
            {
            [array] $UDetails = $AllUsers[$i]
            Write-Host Processing User - $UDetails.UserPrincipalName
            $NewUPN = $UDetails.UserPrincipalName.Replace($productiondomain,$OnMicrosoftdomain)
            Write-Host UPN adjusted as $NewUPN -ForegroundColor Yellow
            [string] $ThumbName = $UDetails.UserPrincipalName.Split("@")[0]+"*"
            [string] $ThumbLocation = Get-ChildItem -Path "C:\GoDaddyTenant\Export\AADUsers\Thumbs" -Filter $ThumbName -ErrorAction SilentlyContinue|Select-Object FullName -ExpandProperty FullName        
            IF (Get-AzureADUser -SearchString $NewUPN -ErrorAction SilentlyContinue)
                {
                Write-Host $NewUPN - User Object Already Exist with the UPN $NewUPN. Skipping User Creation.... -ForegroundColor Red
                }
            Else
                {
                New-AzureADUser -AccountEnabled $False -DisplayName $UDetails.DisplayName -GivenName $UDetails.GivenName  -MailNickName $UDetails.MailNickName  -PreferredLanguage "en-US" -UsageLocation "US" -UserType "Member" -UserPrincipalName $NewUPN -PasswordProfile $PasswordProfile -Country "US"
                }
            $oID = Get-AzureADUser -SearchString $NewUPN -ErrorAction SilentlyContinue
            IF (Test-Path $ThumbLocation)
                {
                $ThumbSize = (Get-ChildItem -LiteralPath $ThumbLocation).Length/1KB
                If ($ThumbSize -lt 80)
                    {
                    Set-AzureADUserThumbnailPhoto -ObjectId $oID.ObjectID -FilePath $ThumbLocation -ErrorAction SilentlyContinue
                    }
                Else
                    {
                    Write-Host Thumb Size is $ThumbSize KB. Please reduce the file size below 80KB -ForegroundColor Red
                    }
                }
            Write-Host $NewUPN - Processing completed -ForegroundColor Green
            }
        }

        Write-Host "Updating Manager Attributes of Users"
        [array] $UserManagerArray = Import-CSV "C:\GoDaddyTenant\Export\AADUsers\UserManager.CSV"
        $Len = $UserManagerArray.Length
        For ($j = 0; $j -lt $Len ; $j++)
            {
            $TargetUser = $UserManagerArray.User[$j].Replace($productiondomain,$OnMicrosoftdomain)
            $TargetUserManager = $UserManagerArray.Manager[$j].Replace($productiondomain,$OnMicrosoftdomain)
            Write-Host Updating manager attribute of $TargetUser to $TargetUserManager -ForegroundColor Yellow
            $UseroID = (Get-AzureADUser -SearchString $TargetUser).ObjectID
            $ManageroID = (Get-AzureADUser -SearchString $TargetUserManager).ObjectID
            Set-AzureADUserManager -ObjectId $UseroID -RefObjectId $ManageroID
            }
    }
Else
    {
    Write-Host Input File Missing at "C:\GoDaddyTenant\Export\AADUsers\AllUsers.CSV". Use the data Collection Script to export the Azure AD User details. -ForegroundColor Red
    }
Disconnect-AzureAD

Leave a Reply