I am trying to get a list of all O365 users from a tenant, and the individual licenses that are assigned to them. The output needs to be in the following format (note that users with more than one license are listed multiple times):
UPN | License user1 | standardpack user1 | plannerstandalone user2 | enterprisepack user2 | power_bi_standard user2 | ems
I can get the information using this:
$groupOfUsers = Get-MsolUser -all | where { $_.IsLicensed -eq $True }
$licenses = foreach ($individual in $groupOfUsers)
{
$allLicenses = $individual.licenses | Select -ExpandProperty AccountSkuId
foreach ($lic in $allLicenses)
{ write-host = $individual.UserPrincipalName $lic }
}
What I would like to do is have this output in a format that I can eventually import into SQL - so a table format or something that I can export to csv would be a great start.
Any help would be appreciated.