Graph PowerShell tip to convert objects to json

preview_player
Показать описание
Here's a quick Graph PowerShell trick that I learned recently. Did you know that every object has a ToJsonString method and it gives you the JSON formatted version of the object?

Now, you could always do the ConvertTo-Json method, but what that does is convert the graph PowerShell .net object model to JSON, which results in lots of these null values and it might not exactly be what you want. So for example, this has 600 odd lines compared to this, which gave me maybe about 10 or 20 lines for the actual object.

Now the other issue with this is if I were to get, for example, the manager field, you will see that it doesn't have the actual value. It has the object type name in it.

Instead we can use the ToJsonString method and it gives you a much more neater format of the object with the manager field expanded already.

I hope you found this useful.

Follow me for more tips and tricks on Graph PowerShell and Entra.
Рекомендации по теме
Комментарии
Автор

This video is gold, I had discovered similar stuff when I was looking the other day on MS Graph, and was shocked when I found out I can make API calls directly from Powershell !! Thank you for sharing this great insight!!

cybersamurai
Автор

Sweet! Thanks for the tip, as that'll come in handy. Definitely much better formatting.

steveng.
Автор

Informative as always Merill! Also, love the domain name #SriLankanVibes!

shehanperera
Автор

This is really cool! I'm really interested in that terminal theme; wow it's nice!

MrMarcLaflamme
Автор

Which version of the Graph Powershell Module are you using ?

alanflorance