Office 365: Generate Office 365 Licenses Report


I always generated Office 365 Licenses report myself so I can get all the data about the users. I have used this report to reclaim licenses or view how the licenses have been used. If you are interested, see the PowerShell Script below.

This script will connect to Azure AD PowerShell (MSOL Service) and get the licensed users, then generate the report with mixed of AD and MSOL data.

Download the Script HERE.

<#
    Script: O365LicenseReport.ps1
    Purpose: Generate a CSV file with all the licensed users with their details
    How to use it? Save this script and run it in a PowerShell. When asked enter the Office 365
    Global Administrator credentials. This script will create a CSV file named
    Office365-Licsenses-Report.csv

    Written By: Anand Venkatachalapathy
#>

Import-Module ActiveDirectory

#Get credentials for the Office 365 Admin account
$msolcred = Get-Credential 

“Connecting to Office 365…”
#Connect to Office 365 cloud
connect-msolservice -credential $msolcred

“Get all currently licensed users from Office 365…”
#Get all Licenses users
$O365Users = Get-MsolUser -All | ? { $_.isLicensed -eq $true }

#Header for the CSV file
“Is Active?`tUsername`tName`tDepartment`tTitle`tLocation`tCountry`tAssigned Licenses`tEmployee Id” `
| Out-File -FilePath .\Office365-Licsenses-Report.csv

#Process all licensed users
foreach ($user in $O365Users)
{
    #Get AD attributes
    $ADUser = Get-ADUser -Filter { UserPrincipalName -eq $user.UserPrincipalName } -Properties EmployeeId,l,Enabled

    #List licenses
    $Licenses = $null
    foreach( $userlicense in $user.Licenses )
    {
        $Licenses += $userlicense.AccountSkuId + ” “
    }

    #Active account or not
    If ($ADUser.Enabled) { $ActiveAccount = “True” } else { $ActiveAccount = “False” }

    #Write it to a CSV file
    $ActiveAccount + “`t” + $ADUser.SamAccountName + “`t” + $User.DisplayName + “`t” + $user.Department + “`t” + `
    $user.title + “`t” + $ADUser.l + “`t” + $user.Country + “`t” + $user.Licenses + “`t ” + $ADUser.employeeId
   
    $ActiveAccount + “`t” + $ADUser.SamAccountName + “`t” + $User.DisplayName + “`t” + $user.Department + “`t” + `
    $user.title + “`t” + $ADUser.l + “`t” + $user.Country + “`t” + $Licenses + “`t ” + $ADUser.employeeId `
    | Out-File -FilePath .\Office365-Licsenses-Report.csv -Append
}
<#
    * * * * * End of Script * * * * *
#>

Advertisements

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