Transition smoothly between Office 365 CSP partners

We’ve had occasional issues with license assignments not holding when switching between Office 365 partners. In our case, we’re usually switching customers from Telstra’s CSP program to Ingram Micro’s.

The usual process is to add Ingram Micro as another CSP partner to the customer’s tenant, then order the same number of Office 365 licenses that already exist in the tenant. The next step is to cancel the existing Office 365 licenses via the original CSP partner.

An issue can arise when cancelling the original licenses where all users become unlicensed until they are manually relicensed.

This can be a big problem if you’re dealing with a large number of users and licenses and you didn’t keep a record of which users have which licenses.

To protect against this, you should report on your users licensing configuration before you cancel your existing Office 365 CSP subscriptions, and be ready to relicense them all in bulk if they are left unlicensed.

Below is a PowerShell script that will export a CSV of the licensing details for all of your users. For each license, it will also export a cmdlet that will re-add the license for you. If your users are left without a license after the original CSP subscriptions are cancelled, you can copy and paste this entire column into PowerShell to relicense everyone in bulk.

Report on Office 365 licenses for your own tenant

Connect-MsolService
$CSVpath = "C:\temp\currentlicenses.csv"
$users = Get-MsolUser | Where-Object {$_.islicensed}
foreach ($user in $users) {
    Write-Host "Exporting license info for $($user.displayname)" -ForegroundColor Yellow
    $licenses = $user.licenses
    foreach ($license in $licenses) {
        $licenseProperties = @{
            DisplayName  = $user.DisplayName
            EmailAddress = $user.UserPrincipalName
            License      = $license.AccountSkuId
            ReAddlicense = "Set-MsolUserLicense -UserPrincipalName $($user.UserPrincipalName) -AddLicenses $($license.AccountSkuId) -ErrorAction SilentlyContinue"
        }
        $forcsv = New-Object psobject -Property $licenseProperties
        $forcsv | Export-CSV -Path $CSVpath -Append -NoTypeInformation
    } 
}

Report on Office 365 licenses for a customer tenant via delegated administration

This script allows you to use your delegated administrator credentials to connect to your customer’s tenant. Before running this script, edit “Customer Name” on the 3rd line to specify the name of the customer that you’d like to export the details for.

Connect-MsolService
$CSVpath = "C:\temp\currentlicenses.csv"
$Customer = Get-MsolPartnerContract | Where-Object {$_.name -match "Customer Name"}
Write-Host "Getting license details for $($customer.name)" -ForegroundColor Green
$users = Get-MsolUser -TenantId $customer.TenantId | Where-Object {$_.islicensed}
foreach ($user in $users) {
    Write-Host "Exporting license info for $($user.displayname)" -ForegroundColor Yellow
    $licenses = $user.licenses
    foreach ($license in $licenses) {
        $licenseProperties = @{
            CustomerName = $customer.Name
            DisplayName  = $user.DisplayName
            EmailAddress = $user.UserPrincipalName
            License      = $license.AccountSkuId
            TenantId     = $customer.TenantId
            ReAddlicense = "Set-MsolUserLicense -UserPrincipalName $($user.UserPrincipalName) -TenantId $($customer.TenantId) -AddLicenses $($license.AccountSkuId) -ErrorAction SilentlyContinue"
        }
        $forcsv = New-Object psobject -Property $licenseProperties
        $forcsv | Export-CSV -Path $CSVpath -Append -NoTypeInformation
    } 
}

How to use the script

  1. Open Visual Studio Code or PowerShell ISE and copy and paste one of the scripts above. If using Visual Studio Code you may need to save it as a PowerShell file first to ensure that you can run it.
  2. Press F5 to run the script
  3. For each license assigned to your users, a row will be exported to a CSV file located at C:\temp\currentlicenses.csv. This row will contain the user and license details, as well as a column called ReAddLicense. This column will contain a cmdlet that you can use to re-add the user’s licenses if it’s removed.Retrieve Cmdlet To Re-Add Licenses
  4. Now that you’ve reported on your users existing licenses, and you’ve purchased the same number of new licenses from your new CSP partner, you can cancel the services with your original CSP partner.
  5. Once the services have been cancelled, connect to Office 365 via PowerShell and check to see whether your users are still licensed. If you’re connecting to your own tenant, run:
    Connect-MsolService
    Get-MsolUser

    If you’re connecting to a customer’s tenant via delegated administration, run:

    Connect-MsolService
    $customer = Get-MsolPartnerContract | Where-Object {$_.name -match "Customer Name"}
    Get-MsolUser -TenantId $customer.TenantId
    
  6. If the users are unlicensed when they shouldn’t be, copy the entire ReAddLicense column from the CSV into the PowerShell session. This will relicense all users to match their original licensing configuration.

Was this article helpful?

Related Articles