Hi everyone,
Environment: MicrosoftGraph and PowerShell
Goal: List all users and display the services they have booked for them
To see the assigned services for a specific user (for example, “clara.korn@company.com”), I use:
Get-MgUserLicenseDetail -UserId "clara.korn@firma.de" | Select-Object SkuPartNumber
When I continued editing the script, I wrote the email address into a variable and adjusted my Get-MgUserLicenseDetail command line:
$mymail = "clara.korn@firma.de"
Get-MgUserLicenseDetail -UserId $mymail | Select-Object SkuPartNumber
Now, however, I have several email addresses that I want to read. I do this by reading all users and retrieving the userPrincipalName. Then, for verification, I output the email address at array position 117. This is the email address of “clara.korn@firma.de”:
$pn = Get-MgUser -All:$True | Select-Object userPrincipalName
echo $pn[117]
No problems here either. The email address is displayed. However, as soon as I want to access the associated services, the variable (array) is not accepted:
Get-MgUserLicenseDetail -UserId $pn[117] | Select-Object SkuPartNumber
I get the following error:
Get-MgUserLicenseDetail : Resource '@{UserPrincipalName=clara.korn@firma.de}' does not exist or one of its queried reference-property objects is not present.
It looks to me as if the entry UserPrincipalName=clara.korn@firma.de is at array position 117. But I only need the email address, without the preceding UserPrincipalName=
How can I accomplish this?
Thanks and happy coding Dirkules