So all, I’m just looking for someone to help me across the finish line with a query.
I’m using the Graph API to query assigned licenses to users from Microsoft Entra.
So far, I can query a single user, and display the assigned licenses, but I’d like to output the information to a PSCustomObject, and that’s where I’m lost.
This bit of code queries the directory and returns all users
$GetUsersUrl = "https://graph.microsoft.com/beta/users"
$Data = Invoke-RestMethod -Uri $GetUsersUrl -Headers $Headers -Method Get
$Result = ($Data | select-object Value).Value
$Users = $Result | select DisplayName,UserPrincipalName,Id
Then I check for userPrincipalName that matches a string and extract the assigned licenses from there
$UPN = ($Users | where {$_.userPrincipalName -like "UPN@domain*"})
$lic = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/$($UPN.id)/licenseDetails" -Headers $Headers -Method Get
$skuPartNumber = $((($lic | select-object Value).Value).skuPartNumber)
Now I just want to take the output I get there and store it in a PSCustomObject along with the information in the $UPN variable.
Ideally, I’d like to use a foreach loop to do this for every user, but I’m not quite there yet (I’m open to help and suggestions on that front as well). Any and all help is appreciated.