1

I am looking to dump a list of MsolAccountSku licenses matched to a UPN from a list.

What I am looking for would be something like the following:

user@domain.com tenant:STANDARDPACK
user2@domain.com tenant:ENTERPRISEPACK

I'm not that great in PS so having a hard time formatting the output and placing it with the UPN.

What I have so far:

$readFile = `
  Get-Content "C:\temp\changelicense.csv"

  foreach($upn in $readFile){

$licensedetails = (Get-MsolUser -UserPrincipalName `
  $upn).Licenses
$licensedetails.AccountSKUId;

if ($licensedetails.Count -gt 0){
  foreach ($i in $licensedetails){
    $i.ServiceStatus 

  }
}
}
0

This is a bit more elaborate than what you asked for.
But I have an old function that you could use that maps each license of a user to the UPN of the user and also shows display name.

The function uses a hash table of the most common SKU names and translates them to the human readable version of the license.

If the SKU's of your Tenant is not on there, just add it to the Hash table. The end result is a nice .csv file that can easily be imported into Excel for example so you can sort on a license or a user to get an overview of who uses what.

Just run the code below to load the function, then run Get-LicenseUsage. This will create a csv file in the directory your PS is currently in (named after the Tenant).

<#
.SYNOPSIS
    Creates a list showing which users has assigned which licenses.

.DESCRIPTION
    Creates a list of all licenses and which user the license is assigned to.
    The list is then output to a csv file, the file is output in the directory the script is run in.
    The filename is automatically created and uses the company name of the Office 365 Tenant.

.EXAMPLE
    Get-LicenseUsage

.NOTES
    Author: Henrik Stanley Mortensen

#>
Function Get-LicenseUsage()
{
    process  {
        $SkuPartFriendlyName = @{
            ########### Enterprise SKU's################
            "STANDARDPACK" = "Enterprise E1"
            "ENTERPRISEPACK" = "Enterprise E3"
            "ENTERPRISEPACKWSCAL" = "Enterprise E4"
            "ENTERPRISEWITHSCAL" = "Enterprise E4"
            "ENTERPRISEPREMIUM_NOPSTNCONF" = "Enterprise E5 w/o PSTN Conferencing"
            "ENTERPRISEPREMIUM " = "Enterprise E5"
            "EMS" = "Enterprise Mobility Pack"
            "AAD_BASIC" = "Azure Active Directory Basic"
            "AAD_PREMIUM" = "Azure Active Directory Premium"
            ############ Business SKU's#################
            "EXCHANGESTANDARD" = "Exchange Online Plan 1"
            "O365_BUSINESS_ESSENTIALS" = "Business Essentials"
            "O365_BUSINESS" = "Business"
            "O365_BUSINESS_PREMIUM" = "Business Premium"
            ############ Standalone Products############
            "POWER_BI_STANDARD" = "Power BI"
            "FLOW_FREE" = "Flow"
            "POWER_BI_PRO" = "Power BI Pro"
            "POWER_BI_STANDALONE" = "Microsoft Power BI for Office 365"
            "PROJECTESSENTIALS" = "Project Online"
            "PROJECTPROFESSIONAL" = "Project Online Professional"
            "PROJECTONLINE_PLAN_1" = "Project Online"
            "PROJECTCLIENT" = "Project Pro for Office 365"
            "RIGHTSMANAGEMENT_ADHOC" = "Rights Management Adhoc"
            "VISIOCLIENT" = "Visio Pro for Office 365"
            "INTUNE_A" = "Intune A Direct"
            "CRMIUR" = "Dynamics CRM URI"
            "MCOMEETADV" = "Skype for Business PSTN Conferencing"
        }

        $lines = @()
        $array= New-Object System.Collections.ArrayList

        foreach($msolUser in (Get-MSOLUser -All | Where-Object {$_.isLicensed -eq $true}))
        {
            $i = 0
            $licenses = New-Object System.Collections.ArrayList
            foreach($SKU in $msolUser.licenses.AccountSku.SkuPartNumber) {
                #Runs the SkuPartNumber through the Friendly Name List to translate the license
                $licenses = $SkuPartFriendlyName.Item($msolUser.licenses[$i].AccountSku.SkuPartNumber)

                #Creates an object with information for the user license
                $lines = @{
                            "Display Name" = "$($msolUser.DisplayName)";
                            "Licenses" = "$licenses";
                            "Login" = "$($msolUser.UserPrincipalName)";
                            }

                $userInfo = New-Object -TypeName psobject -Property $lines

                #Adds the object to an array used for export
                $array.Add($UserInfo)
                $i++
            }
        }
        #Exports the array to a csv file
        $filename = (Get-MsolCompanyInformation).DisplayName + ' License Overview.csv'
        $filename = $filename -replace "/", "."
        $array | Select-Object Login, 'Display Name', Licenses | Export-CSV $filename -Encoding UTF8 -NoTypeInformation -Delimiter ";"
    }
}
0

If you're looking for outputs just by displaying the UPN and their associating SKU. You can just tweak the original script. Unless you're intending to display the Service Plan as well, then you would have to incorporate the ServiceStatus portion

Here is an edit, for just displaying the UPN and SKU

$readFile = Get-Content "C:\temp\changelicense.csv"

foreach($upn in $readFile){

$licensedetails = (Get-MsolUser -UserPrincipalName $upn).Licenses

if ($licensedetails.Count -gt 0){
    foreach ($i in $licensedetails){
        $upn + " " + $licensedetails.accountSKUId }
  }
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.