# Variable (Array) in Get-MgUserLicenseDetail

**URL:** <https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145>\
**Category:** PowerShell Help\
**Created:** [September 3, 2025, 12:01pm UTC](https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145 "2025-09-03T12:01:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirkules](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dirkules](https://forums.powershell.org/u/Dirkules)\
**Post date:** [September 3, 2025, 12:01pm UTC](https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145/1 "2025-09-03T12:01:54Z")

</div>

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](mailto: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

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [September 3, 2025, 12:12pm UTC](https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145/2 "2025-09-03T12:12:15Z")

</div>

You can either use `ExpandProperty` to get just the userPrincipalName values:

```PowerShell
$pn = Get-MgUser -All:$True | Select-Object -ExpandProperty userPrincipalName

```

Or use dot notation to access the property value:

```PowerShell
Get-MgUserLicenseDetail -UserId $pn[117].userPrincipalName | Select-Object SkuPartNumber

```

---

<div class="post-metadata">

**Author:** ![Dirkules](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dirkules](https://forums.powershell.org/u/Dirkules)\
**Post date:** [September 3, 2025, 12:35pm UTC](https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145/3 "2025-09-03T12:35:59Z")

</div>

Thank you very much. It is working now but it was necessary to edit the $pn line to:  
`$pn = Get-MgUser -All:$True`  
or  
`$pn = Get-MgUser`

Another key was your hint with  
`-UserId $pn[117].userPrincipalName`

Dirkules

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 3, 2025, 12:36pm UTC](https://forums.powershell.org/t/variable-array-in-get-mguserlicensedetail/26145/4 "2025-10-03T12:36:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
