Поделиться через


O365 Tidbit - Script to collect license info

Hello All,

Recently I had a customer who had questions about what licenses their users had assigned to them in O365, specifically the questions were

How many E3 SKU’s are assigned to users without an E1?

How many E5 SKU’s are assigned to users without an E1?

Since they were not able to get a satisfactory answer from support or tools, I jumped into PowerShell and came up with this script.

NOTE: Full script is available here

First I made sure that MSOnline was installed and then I import the module thru the following lines

 #Trust repository so we can automate install of MSOnline
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

#PowerShellGet requires NuGet
If(!(Get-PackageProvider -Name NuGet))
{
     Install-PackageProvider -Name NuGet -Force 
}

#Verify MSOnline is installed or Update\Install MSOnline module 
if (Get-InstalledModule -Name MSOnline)
{
     Update-Module MSOnline
     Import-Module MSOnline
}Else
{
     Install-Module MSOnline
     Import-Module MSOnline
}

With the module imported and connecting via Connect-MsolService I then perform two things, the first is to get a high level look at the license by using the following lines

 Get-MsolAccountSku | ForEach-Object {
     $Plan = $_.SkuPartNumber
     $ActiveUnits = $_.ActiveUnits
     $ConsumedUnits = $_.ConsumedUnits
     $LockedOutUnits = $_.LockedOutUnits
     Add-Content -Path "$OutputFolder\$TenantLicenseFile" -Value "$Plan,$ActiveUnits,$ConsumedUnits,$LockedOutUnits,,"
     $_.ServiceStatus | ForEach-Object {
         $Service = $_.ServicePlan.ServiceName
         $ServiceStatus = $_.ProvisioningStatus
         Add-Content -Path "$OutputFolder\$TenantLicenseFile" -Value ",,,,$Service,$ServiceStatus"
     }
 }

Then I gather the sku information for each user using the following:

 Get-MsolUser | ForEach-Object {
     $User = $_.UserPrincipalName
     if($_.IsLicensed)
     {
          $_.Licenses | ForEach-Object {
               $Plan = $_.AccountSkuId
               Switch -Wildcard ($Plan){
                    "*ENTERPRISEPREMIUM" {$E5 = $true}
                    "*ENTERPRISEPACK" {$E3 = $true}
                    "*STANDARDPACK" {$E1 = $true}
               }
               ForEach($Service in $_.ServiceStatus)
               {
                    $ServiceName = $Service.ServicePlan.ServiceType
                    $ServiceStatus = $Service.ProvisioningStatus
                    Add-Content -Path "$OutputFolder\$UserLicenseFile" -Value "$User,$Plan,$Servicename,$ServiceStatus"
               }
        }
}

Then I complete the script by updating variables and providing the responses in a text file.  While this script is very specific hopefully it will help you to manipulate the data out there to get answers for your own questions.

Pax