pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
622 stars 330 forks source link

[BUG]Get-PnPUserProfileProperty #4062

Open ttd-kevinclement opened 6 days ago

ttd-kevinclement commented 6 days ago

Reporting an Issue or Missing Feature

Get-PnPUserProfileProperty returning unexpected results in Runbook

Expected behavior

Expecting a User Profile Properties PowerShell Object

Actual behavior

System.Collections.Generic.SortedDictionary``2[System.String,System.Object]

Steps to reproduce behavior

What is the version of the Cmdlet module you are running?

PnP.PowerShell 2.4.0

Which operating system/environment are you running PnP PowerShell on?

Comments

4061

This command works as intended in our sandbox tenant, when porting to our corporate tenant it behaves as mentioned above.

jackpoz commented 4 days ago

Get-PnPUserProfileProperty return type is SortedDictionary<string, object> , as you can see at https://github.com/pnp/powershell/blob/ebff896b7978fdc09fee8a71006c8659f1c136b7/src/Commands/UserProfiles/GetUserProfileProperty.cs#L38 and https://github.com/pnp/powershell/blob/ebff896b7978fdc09fee8a71006c8659f1c136b7/src/Commands/UserProfiles/GetUserProfileProperty.cs#L154

It uses the standard PowerShell method Cmdlet.WriteObject

Here's an example in PowerShell showing the type of the returned object: image

Note that Runbooks are different than running scripts on the console as there is no actual console for those scripts to write to. When running scripts on a computer with UI, the output is formatted by PowerShell automatically for that UI context, while runbooks don't.

Here are 2 examples. The first is the default behaviour on PowerShell running on my pc: image

The 2nd has | Write-Host which ends up showing the same as you posted: image

A search suggested to use .GetEnumerator(): image

You could try Out-String too, not sure if that would still show the type instead of the content.