How to check your user licenses in Office 365

I recently got asked by one of my clients to check what users were on what plan in their Microsoft Office 365 account. You can imagine my surprise when Microsoft billing told me the only way to do this was to go down each user in the administrative portal, click on them and check the licensing page to see what license is assigned. I asked if there was a way to do this with Powershell and I got sent off to technical support. They found nothing that would do this in their quick technical answers and they would have to get back to me.

After a bit of research on my own, I ended up creating my own script to get the information. Here’s that script:

—————————————————————————————————

# Script to retrieve a licensing report from Office 365 and output it to CSV

# DISCLAIMER

# The sample scripts are not supported under any Microsoft standard support program or service.

# The sample scripts are provided AS IS without warranty of any kind.

# The entire risk arising out of the use or performance of the sample scripts and documentation remains with you.

# Created by Ted Giesler http://blog.cypgrp.com

Function Get-FileName($initialDirectory)

{

     [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) | Out-Null

     $OpenFileDialog = New-Object System.Windows.Forms.SaveFileDialog

     $OpenFileDialog.initialDirectory = $initialDirectory

     $OpenFileDialog.filter = “All files (*.*)| *.*”

     $OpenFileDialog.ShowDialog() | Out-Null

     $OpenFileDialog.filename

     If ($Show -eq “OK”)

        {

        Return $objForm.FileName

        }

    Else

        {

        Write-Error “Operation cancelled by user.”

        Exit

        }

} #end function Get-FileName

# *** Entry Point to Script ***

# load the MSOnline PowerShell Module

# verify that the MSOnline module is installed and import into current powershell session

If (!([System.IO.File]::Exists((“{0}\modules\msonline\Microsoft.Online.Administration.Automation.PSModule.dll” -f $pshome))))

{

    Write-Host “The Microsoft Online Services Module for PowerShell is not installed. The Script cannot continue.”

    write-host “Please download and install the Microsoft Online Services Module.”

    Exit

}

$getModuleResults = Get-Module

If (!$getModuleResults)

{

    Import-Module MSOnline -ErrorAction SilentlyContinue

}

Else

{

    $getModuleResults | ForEach-Object

        {

            If (!($_.Name -eq “MSOnline”))

        {

        Import-Module MSOnline -ErrorAction SilentlyContinue

        }

        }

}

# Connect to Microsoft Online Service

Connect-MsolService -Credential $cred -errorAction silentlyContinue -errorvariable $er

$users = Get-MsolUser -all

# Setup the output file

$defaultfolder = $Env:UserProfile + “\documents”

$outfile = GEt-Filename ($defaultfolder)

$header = “userPrincipaName,usageLocation,isLicensed,accountSKUid,servicePlan1,provisioningStatus1,servicePlan2,provisioningStatus2,servicePlan3,provisioningStatus3,servicePlan4,provisioningStatus4,servicePlan5,provisioningStatus5”

Out-File -FilePath $outfile -InputObject $header

# Write-Host $header

foreach($usr in $users)

{

    $lineOut=$usr.UserPrincipalName + “,” + $usr.usageLocation + “,” + $usr.isLicensed + “,”

    foreach($lic in $usr.Licenses)

    {

        $lineOut = $lineOut + $lic.AccountSkuID

        foreach($s in $lic.ServiceStatus)

        {

            $lineout = $lineout + $s.ServicePlan.ServiceName + “,” + $s.ProvisioningStatus +”,”

        }

    }

    Out-File -FilePath $outfile -Append -NoClobber -InputObject $lineOut

    # Write-Host $lineOut

    $lineOut = $null

}

Write-Host -ForeGroundColor BLue “Please review your output file at ” $outFile

————————————————————————————————————————–

This script will create a comma separated file showing each user and each license category that user has a license. Unfortuantely, this does not match nicely to the Office 365 plans. You will have to add the specific licenses together to try and match your Office 365 Plan licenses.

Hopefully this will help others looking for the same type of answers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s