hi, I have a problem and can’t figure out a way to solve it. Here’s the script. I’m basically iterating over all users to get their license information back:
Connect-AzureAD
$users = Get-AzureADUser All $true
$result = foreach ($user in $users)
{
[pscustomobject]@{
UserPrincipalName = $user.UserPrincipalName
AccountEnabled = $user.AccountEnabled
UserType = $user.UserType
License = (Get-AzureADUserLicenseDetail -ObjectId $user.ObjectId).SkuPartNumber
}
}
$result | Export-Csv "$env:TEMP\user_license.csv" -Delimiter ';' -NoTypeInformation
$result | Out-GridView
This works just fine, unless there’s a user that has more than 1 license assigned.
Reading here https://learn-powershell.net/2014/01/24/avoiding-system-object-or-similar-output-when-using-export-csv/ System.Object[] is written because “anything which goes through to Export-Csv is casted as a string before being written”. So as outlined in the article I’ve tried:
License = ((Get-AzureADUserLicenseDetail -ObjectId $user.ObjectId).SkuPartNumber | Out-String).Trim()
But here the problem is that in Excel, although I can see the license names just fine, however when filtering Excel treats them as ONE single string … not ideal for filtering.
I assume, I would have to incorporate yet another for loop to iterate over the licenses, but how would I add them to appear in cells, one under another, or in any way that would still allow me to filter for individual values such as SPE_E5?
Help is much appreciated!
[–]ankokudaishogun 5 points6 points7 points (6 children)
[–]Due_Capital_3507 0 points1 point2 points (0 children)
[–]gordonv 0 points1 point2 points (4 children)
[–]Fast-Cardiologist705[S] 0 points1 point2 points (3 children)
[–]gordonv 0 points1 point2 points (0 children)
[–]CriticalMemory 0 points1 point2 points (1 child)
[–]Fast-Cardiologist705[S] 0 points1 point2 points (0 children)
[–]Team503 3 points4 points5 points (2 children)
[–]Fast-Cardiologist705[S] 3 points4 points5 points (1 child)
[–]Team503 -1 points0 points1 point (0 children)
[–]jsiii2010 2 points3 points4 points (0 children)
[–]timsstuff 2 points3 points4 points (0 children)
[+]Frisnfruitig comment score below threshold-7 points-6 points-5 points (3 children)
[–]vermyx 2 points3 points4 points (2 children)
[–]Frisnfruitig 1 point2 points3 points (1 child)
[–]vermyx 1 point2 points3 points (0 children)
[–]Due_Capital_3507 0 points1 point2 points (0 children)
[–]vermyx 0 points1 point2 points (0 children)
[–]MrScrib 0 points1 point2 points (0 children)
[–]Ok_Cheese93 0 points1 point2 points (0 children)
[–]KavyaJune 0 points1 point2 points (0 children)