BasicLicenseReport.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID 868ed289-b508-46d0-9e8e-5eb0be4e112c .AUTHOR Aaron Guilmette .COMPANYNAME Microsoft .COPYRIGHT 2020 .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .DESCRIPTION The most basic Office 365 SKU report. .PRIVATEDATA #> <# .SYNOPSIS The most basic Office 365 SKU report. .PARAMETER Output The output file. By default, it's Date_LicenseReport.CSV. It doesn't get more basic. .PARAMETER ReportType Two options: - PerSKU lists all of the users with a particular SKU assigned. If no SKU value is specified, it will give you a menu. I'd suggest using the menu so you can see what you have. - PerUser lists all of the SKUs that a single user has. I've trimmed the tenant name, and then joined them together in a single column with the ";" character. .PARAMETER SkuValue Optional, and you'll need to specify it in tenant:SKU format. If you don't provide one, a list will be provided for you. #> param ( $Output = (Get-Date -Format yyyy-MM-dd) + "_LicenseReport.csv", [ValidateSet('PerSKU', 'PerUser')]$ReportType, [ValidateScript({ if ($_ -notmatch "\w*\:\w*") { throw "`$SkuValue must be in the form of tenant:SKUID" } $true })]$SkuValue ) $Users = Get-MsolUser $TotalUsers = $Users.Count function ChooseSKU { # Get SKUs and put into a menu $Skus = Get-MsolAccountSku $SkuMenu = @{ } $Choice = $null Write-Host -Fore Yellow "Select SKU" For ($i = 1; $i -le $Skus.Count; $i++) { Write-Host "$i. $($Skus[$i - 1].AccountSkuId)" $SkuMenu.Add($i, ($Skus[$i - 1].AccountSkuId)) } If (!($SkuValue)) { [int]$Skuselection = Read-Host "Enter value for SKU to report on" $SkuValue = $SkuMenu.Item($Skuselection) } Write-Host -NoNewline "Select SKU is: "; Write-Host -ForegroundColor Green "$($SkuValue)" $Choice = Read-Host "Correct? [Y/N]" while ($Choice -ne "Y") { Exit } } If ($ReportType -eq "PerSKU" -and !$SkuValue) { ChooseSKU } $i = 1 $global:Report = @() switch ($ReportType) { PerUser { foreach ($User in $Users) { Write-Progress -Activity "Processing user $($User.DisplayName) - $($i)/$TotalUsers" -PercentComplete (($i/$TotalUsers) *100) $UserData = [ordered]@{ DisplayName = $User.DisplayName UserPrincipalName = $User.UserPrincipalName AssignedSKUs = ($User.Licenses.AccountSkuId | % { ($_ -split ":")[1] }) -join ";" } $UserDataObj = New-Object PSObject -Property $UserData $global:Report += $UserDataObj $Obj = $null $i++ } } PerSKU { foreach ($User in $Users) { Write-Progress -Activity "Processing user $($User.DisplayName) - $($i)/$TotalUsers" -PercentComplete (($i/$TotalUsers) * 100) $UserData = $null If ($User.Licenses.AccountSkuId -match $SkuValue) { $UserData = [ordered]@{ DisplayName = $User.DisplayName UserPrincipalName = $User.UserPrincipalName AssignedSKUs = $SkuValue.Split(":")[1] } $Obj = New-Object PSObject -Property $UserData $global:Report += $Obj } $i++ } } } $Report | Export-Csv $Output -Force |