forked from 12Knocksinna/Office365itpros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportLicenseAssignmentsToUsers.Ps1
28 lines (26 loc) · 1.16 KB
/
ReportLicenseAssignmentsToUsers.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
# Create report of licenses assigned to users in a tenant
$Report = @()
$Users = Get-MsolUser -All | where {$_.isLicensed -eq $true}
Write-Host "Processing Users"
ForEach ($User in $Users) {
$SKUs = @(Get-MsolUser -UserPrincipalName $User.UserPrincipalName | Select -ExpandProperty Licenses)
ForEach ($Sku in $Skus) {
$ReportLine = [PSCustomObject][Ordered]@{
User = $User.UserPrincipalName
SKU = $Sku.AccountSkuId.Split(":")[1]
Name = $User.DisplayName
Title = $User.Title
City = $User.City
Country = $User.UsageLocation
Department = $User.Department
CreatedOn = Get-Date($User.WhenCreated) -Format g}
$Report += $ReportLine }
}
Cls
Write-Host "License information"
$Groupdata = $Report | Group-Object -Property SKU
$Groupdata | Sort Count -Descending | Select Name, Count
# Set sort properties so that we get ascending sorts for one property after another
$Sort1 = @{Expression='SKU'; Ascending=$true }
$Sort2 = @{Expression='Name'; Ascending=$true }
$Report | Select SKU, Name, User | Sort-Object $Sort1, $Sort2 | Export-CSV c:\Temp\UserLicenses.CSV -NoTypeInformation