O365 Licenses for MS Dynamics CRM Online

So our Dynamics CRM Online was recently migrated from the old hosted version to the new version hosted through our Office 365 Tenant. Now we have a new licensing property available in the O365 admin portal for assigning licenses to CRM.
Pretty simple so far, but the question was asked "How many users are licensed according to O365?"....in comes powershell!


Apparently the CRM admin was able to pull the number of licensed users in CRM and wanted to make sure that the numbers were the same as users licensed in O365.

The licenses for an O365 user are stored in the Licenses field of their MSOLUser object.
Great! Now we can actually grab all of our users and dump it out into a csv for the CRM admins. If you really wanted to run this on a regular basis I would output it to HTML and email it but I'll leave that to you!
Here's the code that I use to create the csv file.

#get all the licensed users
$users=Get-MsolUser -All | Where-Object { $_.isLicensed -eq "TRUE" }
#setup a var to hold your output
$CRMlicensedusers=@()
#loop through the users
foreach($user in $users){
    #the Licenses.AccountSkuID is what we're interested in
    Foreach($license in $user.licenses.accountskuid){
        #look for %yourtenantname%:CRMSTANDARD
        #so for me its Anexinet:CRMSTANDARD
        if ($license -eq "Anexinet:CRMSTANDARD") {
            #add the License value to the object, this gives us a single value
            $user | Add-Member -Type NoteProperty -Name License -Value $license
            #push the object into the output
            $CRMlicensedusers+=$user
        }
    }
}
#Convert your output object to a CSV file, we're only interested in the License and first,last,UPN,and displaynames
$CRMlicensedusers | Select-Object FirstName,LastName,DisplayName,UserPrincipalName,License | Export-Csv crmlicensedusers.csv -NoTypeInformation

Grab it from GitHub: https://github.com/mikecessna/Office365Scripts/blob/master/Get-MSOL-CRMlicenses.ps1

This is just the tip of the iceberg for licensing since there are sub licenses that can be assigned within O365 but I'll leave that for another post.

Labels: , ,