Tag: migrate

  • Migrate Office365 Photos to AD

    Many of my customers have Office365 and have been using Skype for Business for sometime now. It is likely that your organization users have uploaded their profile picture. Now only if there was a way to sync those pictures back to your AD – so it looks neat & nice. There is a way!

    #MigrateOffice365PhotosToAD.ps1
    
    function Get-Office365Photo($EmailAddress,$Credential) {
        $wc = New-Object System.Net.WebClient
        $wc.credentials = $Credential
        # Build the URL that'll return the jpeg of the user's photo
        $url = "https://outlook.office365.com/ews/exchange.asmx/s/GetUserPhoto?email=$EmailAddress&size=HR96x96"
        # Build a path to export it to (.\[email protected])
        $outPath = "$pwd\$EmailAddress.jpg"
        try { 
            # Download the image and save it to the current directory
            $wc.DownloadFile($url,$outPath)
            return $outPath
        } catch { throw $_ }
    }
    
    function Upload-ADPhoto($Username,$FilePath) {
        # Import the photo into a variable as a byte array
        $photo = [byte[]](Get-Content $FilePath -Encoding byte)
        # Replace the current value of thumbnailPhoto with the byte array from above
        Set-ADUser $Username -Replace @{ThumbnailPhoto=$photo}
    }
    
    # Get the credential to allow us to download the images
    $Cred = Get-Credential -Message "Please enter your Office 365 Credentials"
    
    # Get every mail-enabled AD user
    $users = Get-ADUser -ldapfilter '(mail=*)' -properties mail
    
    # For each of the mail-enabled users...
    foreach ($user in $users) {
        try {
            # Download the photo
            $photoPath = Get-Office365Photo -EmailAddress $user.mail -Credential $Cred
            # Upload the photo
            Upload-ADPhoto -Username $user -FilePath $photoPath
        } catch {
            Write-Warning "Unable to update image for $($user.mail)"
        }
    }

    Source

  • Cannot migrate user from Exchange 2010 to Exchange Online

    So I came across this error while migrating some accounts from On-Premise Exchange 2010 Server to Exchange Online.

    Error: The subscription for the migration user [email protected] couldn’t be loaded. The following error was encountered: A subscription wasn’t found for this user.

    migrationbatch

    In short, there is an address conflict between the user properties of the exchange server and the synced object on Office365. Lets go back to the basics to get this fixed.

    Environment: Exchange 2010 in Hybrid Mode with Exchange Online. Migrating accounts using a staged migration approach. The problematic user in Exchange Online is properly licensed.

    Setup for Staged Migration.

    • Exchange Online: Stop the problematic migration batch and delete it
    • Exchange 2010: Even though the user account may show that it is a Remote mailbox or just a User Mailbox. Right click and hit Disable. (This will remove the exchange properties for the user.)
      option1
    •  option2
    • Exchange 2010: Search your Exchange database and find the user’s on-premise mailbox. This is easier if you have just 1 or 2 databases. In an enterprise environment this may be a task by itself. Open EMS and type the following:
      Get-MailboxStatistics -Database <your exchange database name>

      If the result set it too long, you may want to save the contents to a file.

      Get-MailboxStatistics -Database yourexchangedatabase > C:\my_exchange_users.txt

      Open the file and search for the user you disabled in step 2

    • Now you need to delete the problematic user in Exchange Online. Open up PowerShell ISE and type the following:
      Import-Module MSOnline
      $O365Cred = Get-Credential
      $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
      Import-PSSession $O365Session
      Connect-MsolService –Credential $O365Cred

      After supplying the Global Admin credentials and successfully logging in, do the following:

      Remove-MsolUser -UserPrincipalName [email protected]
      Remove-MsolUser -UserPrincipalName [email protected] -RemoveFromRecycleBin
    • Now the object is not in Exchange 2010 and Exchange Online
    • Attach the user back to Exchange 2010. Open up EMS and type the following:
      Connect-Mailbox -Identity "John Doe" -Database "YourExchangeDatabase" -User "John Doe"
    • The mailbox should show up in Exchange 2010. Make sure that the SMTP address includes: [email protected] address.
    • In a  few minutes DirSync will sync the object back to Exchange Online (This depends on your DirSync time interval)
    • When the user shows up – make sure you assign the user a license in Exchange Online.
    • Start a new migration batch for the user.
    • Migration will go through as expected.