In office 365 environment you can check users and assigned licenses through the portal. However the portal does not provide any facility (at least as of now, may be in future) to check or create report on bulk users. The best way is using a PowerShell script to create reports you like for your organisation. Handy in situations if you are doing this activity on a regular basis.
Before you begin
You will need couple of things before you can execute the commands / scripts mentioned below. You can refer to my earlier blog on how to connect to O365 using PowerShell (https://girishzalke.wordpress.com/2014/02/24/powershell-connecting-to-o365/).
Get User from O365
To retrieve an individual user or list of users, you can use the Get-MsolUser cmdlet. You can retrieve individual users using parameters like Object ID / UserPrincipalName OR you can retrieve list of users using parameters like SearchString / DomainName / etc.
Word of caution; when using Get-MsolUser cmdlet to retrieve list of users you may have to specify value for “MaxResults” parameter (integer value). This limits the search results to the value specified for the parameter.
For more information on Get-MsolUser visit http://technet.microsoft.com/en-us/library/dn194133.aspx
For the purpose of this article I will be using “UserPrincipleName” to retrieve user.
$SelectedUser = Get-MsolUser -UserPrincipalName $PrincipalID
The command will get user based upon the supplied UserPrincipalName supplied in $PrincipalID. We store it in a variable $SelectedUser for now. We will use this to get the details of the licenses allocated for the user.
Get Licenses
The user object returned from the command above has various properties. Since we are interested in Licenses, there are 2 main properties we need to look at;
-
isLicensed: This is “Yes / No” and indicates whether there are any licenses allocated to the user. The license may be CRM Dynamics Online, SharePoint Online, etc.
-
Licenses: Collection of licenses allocated to the user. (We are interested in this !!!)
Licenses is a collection of License object. The property we are interested within this object is “AccountSkuId”. This property contains the name of License in the following format “{office 365 organisation name}:{License Name}”
For example if the Organisation Name is “GZOrg” you will see the AccountSkuId as follows;
-
GZOrg: CRMSTANDARD – CRM Standard License.
-
GZOrg: SHAREPOINTSTANDARD – SharePoint Standard License.
-
etc.
So putting it together as a function ….
#Function to check single user using Principle ID.
Function Check-UserInO365($PrincipalID)
{
$ErrorActionPreference = "Stop"
try
{
$Licenses = ""
$SelectedUser = Get-MsolUser -UserPrincipalName $PrincipalID
$Licenses = ($SelectedUser.Licenses | select -expand AccountSkuId) -join ","
New-Object PSObject -property @{ DisplayName = $SelectedUser.DisplayName ; UserPrincipalName = $SelectedUser.UserPrincipalName; Licenses= $Licenses; Status = "User Found"}
}
catch
{
New-Object PSObject -property @{ DisplayName = "" ; UserPrincipalName = $PrincipalID; Licenses= $Licenses; Status = "User Not Found"}
}
}
This will produce the following result ….
| Status Licenses DisplayName UserPrincipalName —— ———- —————- ———————- User Found GZOrg:SHAREPOINTSTANDARD, … User 1 user1@gzorg.on… |
Now you could tweak the above function and read a list of Principal names from a CSV file and then check the users against Office 365.
Tweaked function ….
#Function to check bulk users.
Function Check-UsersInO365([string] $CSVFile)
{
$UsersToBeChecked = Import-Csv $CSVFile
$ErrorActionPreference = "Stop"
foreach($User in $UsersToBeChecked)
{
$PrincipalID = $User.PrincipalID
try
{
$Licenses = ""
$SelectedUser = Get-MsolUser -UserPrincipalName $PrincipalID
$Licenses = ($SelectedUser.Licenses | select -expand AccountSkuId) -join ","
New-Object PSObject -property @{ DisplayName = $SelectedUser.DisplayName ; UserPrincipalName = $SelectedUser.UserPrincipalName; Licenses= $Licenses; Status = "User Found"}
}
catch
{
New-Object PSObject -property @{ DisplayName = "" ; UserPrincipalName = $PrincipalID; Licenses= $Licenses; Status = "User Not Found"}
}
}
}
Note: For the above example, the CSV File needs to have a “PrincipalID” column.
Result ….
| Status Licenses DisplayName UserPrincipalName —— ———- —————- ———————- User Found GZOrg:SHAREPOINTSTANDARD, … User 1 user1@gzorg.on… User Found GZOrg:CRMSTANDARD User 2 user2@gzorg.on… User Not Found user3@gzorg.on… User Found GZOrg:SHAREPOINTSTANDARD User 4 user4@gzorg.on… |
Leave a comment