-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-AzureADUserLicenseSummary.ps1
61 lines (51 loc) · 2.04 KB
/
Get-AzureADUserLicenseSummary.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Get-AzureADUserLicenseSummary {
<#
.SYNOPSIS
Gets a summary of users license allocation and enabled plans in readable format.
.DESCRIPTION
Enables you to quickly identify O365 license allocated to a user as well as the plans that are enabled as part of their license.
.PARAMETER ObjectID
Specifies the ID (as a UPN or ObjectId) of a user in Azure AD.
.EXAMPLE
Get-AzureADUserLicenseSummary [email protected]
.EXAMPLE
$users = '[email protected]','[email protected]'
Get-AzureADUserLicenseSummary $users
.NOTES
Requires connection to AzureAD
Use Connect-AzureAD to establish connection
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline,
ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$ObjectID
)
process {
foreach ($user in $ObjectID) {
try {
$userobj = Get-AzureADUser -ObjectId $user -ErrorAction stop
if ($userobj) {
$UserLicenses = Get-AzureADUserLicenseDetail -ObjectId $user -ErrorAction stop
}
[pscustomobject]@{
UserPrincipalName = $userobj.UserPrincipalName
usagelocation = $userobj.usagelocation
Licenses = ($UserLicenses.skupartnumber).replace('STANDARDPACK','ENTERPRISE E1').replace('ENTERPRISEPACK','ENTERPRISE E3').replace('ENTERPRISEPREMIUM','ENTERPRISE E5').replace('SHAREPOINTSTANDARD','SHAREPOINT ONLINE')
Plans = ($UserLicenses.serviceplans | Where-Object ProvisioningStatus -EQ Success).serviceplanname
}
}
catch {
[PSCustomObject]@{
UserPrincipalName = $user
usagelocation = $null
Licenses = $null
Plans = $null
}
}
}
}
}