# Select -expandproperty and other attributes

**URL:** <https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714>\
**Category:** PowerShell Help\
**Created:** [November 15, 2017, 11:51am UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714 "2017-11-15T11:51:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 15, 2017, 11:51am UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/1 "2017-11-15T11:51:19Z")

</div>

So I know I can do this and get the expanded properties of a value

```
get-msoluser -userprincipalname test@test.com | select -expandproperty licenses
```

However I want to run through all of my users and see what they are licensed for. I need to use -expand property because some of the users are licensed for multiple items and it doesn’t show them all if I don’t expand the property. But I can’t expand the property and get say UPN so I can link up the username to the licenses.

What’s the best way to get both the expanded property and the single valued attribute?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 15, 2017, 11:56am UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/2 "2017-11-15T11:56:07Z")

</div>

You can’t really do both at the same time. You’ll want to get your users and then enumerate them in a ForEach. That’ll get you your user information; within the ForEach, you can expand out licenses on a per-user basis.

It’d be helpful to know what kind of output you’re thinking of - I’d be able to offer something more concrete.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 15, 2017, 12:27pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/3 "2017-11-15T12:27:01Z")

</div>

I figured that was the case.

I just want an output of userprincipalname and licenses, here is an example of what one user looks like if I run this:

```
get-msoluser -All | select licenses, userprincipalname
```

Licenses UserPrincipalName

* * *

{domain:MCOMEETADV\_GOV, domain:VISIOCLIENT\_GOV, Domain:PROJECTCLIENT\_GOV, … [username@domain.com](mailto:username@domain.com)

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 15, 2017, 12:28pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/4 "2017-11-15T12:28:27Z")

</div>

So, I’m guessing what you don’t like about the current output is the {} syntax used to show a collection of licenses.

I would go through each user, and expand their licenses. For each license, I’d output a new object having the UPN as one property, and a single license as another property. That will get you something a bit more like what you want.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 15, 2017, 12:49pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/5 "2017-11-15T12:49:29Z")

</div>

The {} is fine, it’s that if there are more than 3 licenses it cuts off the rest of them. I’d actually prefer the whole collection expanded to each individual UPN but I am fine with doing something like this:

UPN License

* * *

[test@domain.com](mailto:test@domain.com) domain:MCOMEETADV\_GOV  
[test@domain.com](mailto:test@domain.com) domain:VISIOCLIENT\_GOV  
[test@domain.com](mailto:test@domain.com) Domain:PROJECTCLIENT\_GOV

I think I have some code I hijacked from the internet to give me AD group memberships report that does something similar to this, I will look into it. I’m still very new to custom objects, at least ones that require foreach statements 😉

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 15, 2017, 12:54pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/6 "2017-11-15T12:54:09Z")

</div>

Yeah, so keep in mind that PowerShell wants to deal with objects. It’s not a report generator. You could use Group-Object or something to re-group things by user. But the output above is what you’re going to need to be happy with ;).

```
# Assuming $users has your users
# Assuming $users.upn is the UPN, $users.licenses is licenses
ForEach ($user in $users) {
 ForEach ($license in $user.licenses) {
  $props = @{'UPN'=$user.upn
             'License' = $license}
  New-Object -Type PSObject -Prop $props
 }
}
```

Something vaguely like that.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 15, 2017, 2:21pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/7 "2017-11-15T14:21:55Z")

</div>

Thanks Don, that helped a lot. For clarification is the $license variable taking whatever value is in $user.licenses.accountskuid?

For anyone else who might run into this in the future here is what I did to get everything working:

```
$Users = Get-Msoluser -all 

ForEach ($user in $users) {
 ForEach ($license in $user.licenses.accountskuid) {
  $props = @{'UPN'=$user.userprincipalname
             'License' = $license}
  New-Object -Type PSObject -Prop $props
 }
}
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 15, 2017, 2:22pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/8 "2017-11-15T14:22:59Z")

</div>

No, it’s taking whatever is in $licenses, which would be $user.licenses. You’d need to further enumerate accountskuid or any sub-properties.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 15, 2017, 2:30pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/9 "2017-11-15T14:30:28Z")

</div>

Ok, that’s what I thought. In my code I enumerated further with the accountskuid and got exactly what I needed.

Thanks again for your help.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/select-expandproperty-and-other-attributes/9714/10 "2024-05-16T20:37:11Z")

</div>


