# Office365 find license script

**URL:** <https://forums.powershell.org/t/office365-find-license-script/3789>\
**Category:** PowerShell Help\
**Created:** [February 20, 2015, 9:42am UTC](https://forums.powershell.org/t/office365-find-license-script/3789 "2015-02-20T09:42:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![iain-alexander](https://avatars.discourse-cdn.com/v4/letter/i/87869e/32.png) [@iain-alexander](https://forums.powershell.org/u/iain-alexander)\
**Post date:** [February 20, 2015, 9:42am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/1 "2015-02-20T09:42:32Z")

</div>

Hi

I have created a script that connects to our Office365 tenancy and finds the license assigned to each user (amongst other things)

```
Get-MsolUser -All | where {$_.IsLicensed -eq "true" } | 
Select-Object -Property DisplayName, Licenses, MobilePhone, UserPrincipalName
```

This works fine but shows the license in curly braces e.g. {“my tenancy”:STANDARDPACK} which when I pipe to export-csv then appears as System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]

Anyone know how I can resolve that so it shows the same as when it is output to the screen please?

---

<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:** [February 20, 2015, 9:48am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/2 "2015-02-20T09:48:32Z")

</div>

That’s because Licenses is not a property; it is a collection that can contain multiple values. The curly bracket thing is what PowerShell does when you ask it to display a collection as a string on the screen. When you export, the curly bracket thing doesn’t come into play, and so you get the type name of the collection.

```
Select-Object -Property DisplayName, @{n='Licenses';e={ ($_ | Select -Expand Licenses) -join "/" }, MobilePhone, UserPrincipalName
```

Will output a slash-delimited list of licenses. You can fiddle with that to get the look you want. I’m just guessing on what you might want to see, so this will probably require some adjusting.

---

<div class="post-metadata">

**Author:** ![iain-alexander](https://avatars.discourse-cdn.com/v4/letter/i/87869e/32.png) [@iain-alexander](https://forums.powershell.org/u/iain-alexander)\
**Post date:** [February 20, 2015, 10:13am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/3 "2015-02-20T10:13:05Z")

</div>

Hmm - when I ran

```
Get-MsolUser -MaxResults 1 | gm
```
 it listed Licenses as a property.

Tried your suggestion and it now shows as Microsoft.Online.Administration.UserLicense both on screen and in csv

---

<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:** [February 20, 2015, 11:25am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/4 "2015-02-20T11:25:59Z")

</div>

It’s a property that contains a collection. Unforunately, I can’t run the same command so I cannot troubleshoot that for you. The syntax I gave may not be exactly correct for your situation, but it’s the general direction. It seems like the property is a collection of other objects, which means additional selecting would need to be done. Let me see what I can research.

---

<div class="post-metadata">

**Author:** ![iain-alexander](https://avatars.discourse-cdn.com/v4/letter/i/87869e/32.png) [@iain-alexander](https://forums.powershell.org/u/iain-alexander)\
**Post date:** [February 20, 2015, 11:32am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/5 "2015-02-20T11:32:40Z")

</div>

Ok thanks

---

<div class="post-metadata">

**Author:** ![william-parry](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@william-parry](https://forums.powershell.org/u/william-parry)\
**Post date:** [February 21, 2015, 11:40am UTC](https://forums.powershell.org/t/office365-find-license-script/3789/6 "2015-02-21T11:40:26Z")

</div>

Try this:

`Get-MsolUser -MaxResults 1 | select -expandproperty licenses `

I think that’ll show what “sub property” of licenses it is you want.

---

<div class="post-metadata">

**Author:** ![william-parry](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@william-parry](https://forums.powershell.org/u/william-parry)\
**Post date:** [February 21, 2015, 9:20pm UTC](https://forums.powershell.org/t/office365-find-license-script/3789/7 "2015-02-21T21:20:51Z")

</div>

I think what you want, sorry if you would have found this yourself, is:

`Get-MsolUser -All | where {$.IsLicensed -eq “true” } |
Select-Object -Property DisplayName, @{name=“licenses”;expression={$.licenses.accountskuid}}, MobilePhone, UserPrincipalName`

The property you saw before adding Export-CSV to the pipeline was actually the licenses.accountskuid property.

---

<div class="post-metadata">

**Author:** ![iain-alexander](https://avatars.discourse-cdn.com/v4/letter/i/87869e/32.png) [@iain-alexander](https://forums.powershell.org/u/iain-alexander)\
**Post date:** [February 22, 2015, 9:01pm UTC](https://forums.powershell.org/t/office365-find-license-script/3789/8 "2015-02-22T21:01:23Z")

</div>

Ah that got it thanks William. I had tried {$\_.accountskuid} and not got anywhere with it.

Your help is much appreciated everyone

---

<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:46pm UTC](https://forums.powershell.org/t/office365-find-license-script/3789/9 "2024-05-16T20:46:20Z")

</div>


