Hi,
You can create a PSCustomObject with the given column headers.
Connect-MsolService
$report = @()
$usersGroup = @()
$userNames2check = get-content <txt file with UPNs of users I need to check>
foreach ($username in $userNames2check)
{
$usersGroup += Get-MsolUser -UserPrincipalName $username
}
foreach ($user in $usersGroup)
{
if ($user.Licenses -ne "$null")
{
foreach ($license in $user.Licenses)
{
if($license.GroupsAssigningLicense[0].ToString() -eq $user.ObjectId)
{
Write-Host -foregroundcolor Cyan $user.UserPrincipalName " " -NoNewline; write-host -foregroundcolor Green $license.AccountSkuId -NoNewline; write-host -ForegroundColor White " Direct assignment"
$report += [pscustomobject]@{
USER = $user.UserPrincipalName
LICENSE = $license.AccountSkuId
ASSIGNMENT = "Direct assignment"
}
}
else{
write-host -foregroundcolor Cyan $user.UserPrincipalName " " -NoNewline; write-host -foregroundcolor Yellow $license.AccountSkuId -NoNewline; write-host -ForegroundColor White " Assigned by group"
$report += [pscustomobject]@{
USER = $user.UserPrincipalName
LICENSE = $license.AccountSkuId
ASSIGNMENT = "Assinged by group"
}
}
}
}
}
Best Regards,
Ian Xue
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.