Last active
October 4, 2018 16:47
-
-
Save exactmike/6a00749968485900c131c4b194538eb4 to your computer and use it in GitHub Desktop.
Office 365 License Reporting with the MSOnline Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Get the available Skus and Usage from the tenant | |
| Get-MsolAccountSku | Select-Object SkuPartNumber,ActiveUnits,ConsumedUnits,@{n='AvailableUnits';e={$_.ActiveUnits-$_.ConsumedUnits}} -OutVariable AllSkus | |
| #Specify which skus you want to specifically report on | |
| $SkusToReportOn = @('STANDARDPACK','ENTERPRISEPACK','ENTERPRISEPREMIUM') | |
| #Report on Users/Sku Usage | |
| $AllLicensedUsers = Get-MsolUser -all | ? IsLicensed -eq $true | Select DisplayName,UserPrincipalName,IsLicensed,@{n='Skus';e={@($_.Licenses.AccountSkuID)}} | |
| #Below expands licensed users so that for each Sku in SkusToReportOn there would be an entry for the user if the user has more than one of them assigned | |
| $ExpandedSkuUsers = @( | |
| foreach ($lu in $AllLicensedUsers) | |
| { | |
| $SkusHeld = @() | |
| foreach ($s in $SkusToReportOn) | |
| { | |
| $splitskus = @($lu.skus | ForEach-Object {$_.split(':')[1]}) | |
| if ($splitskus -contains $s) | |
| { | |
| [pscustomobject]@{ | |
| DisplayName = $lu.DisplayName | |
| UserPrincipalName = $lu.UserPrincipalName | |
| IsLicensed = $lu.IsLicensed | |
| Sku = $s | |
| AllSkus = $($splitskus -join ';') | |
| } | |
| $SkusHeld += $s | |
| } | |
| } | |
| if ($SkusHeld.Count -eq 0) | |
| { | |
| [pscustomobject]@{ | |
| DisplayName = $lu.DisplayName | |
| UserPrincipalName = $lu.UserPrincipalName | |
| IsLicensed = $lu.IsLicensed | |
| Sku = $null | |
| AllSkus = $($splitskus -join ';') | |
| } | |
| } | |
| }) | |
| #Counts Per License Sku | |
| $ExpandedSkuUsers | group sku -NoElement | |
| #Users with License Detail (one object per user/SkusToReportOn) | |
| $ExpandedSkuUsers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment