Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Calling Microsoft Graph with PnP PowerShell
April 15
Calling Microsoft Graph with PnP PowerShell

As an M365 Admin it’s not tough to see that the future is hidden somewhere in the Microsoft Graph. And this particular M365 Admin would like to get there using his favorite tool, PowerShell. Microsoft released the Graph SDK, but it didn’t really scratch the itch for me. I found it confusing and really tough to use. But, as much as I ignored it, the Graph didn’t go away. With increased frequency there would be some little tidbit of information I’d want and the answer would be, “It’s in the Graph.” Grrrrr.

I was poking the M365 PnP Samples and stumbled across this little gem, Authenticate with and call the Microsoft Graph. That looked promising, I can work with that. I fired up PowerShell, loaded the PnP.PowerShell, fired up the Graph Explorer and started working.

It went well enough that I wrote a little wrapper function around it and published it to GitHub. It’s called Get-TKPnPGraphURI and it looks like this:

image

Get-TKPnPGraphURI -uri https://graph.microsoft.com/v1.0/me/

Get-TKPnPGraphURI -uri https://graph.microsoft.com/v1.0/users | select displayName,userPrincipalName,id

It uses PnP.PowerShell, so you’ll need that module installed, and you’ll need to connect with Connect-PnPOnline. From there you can pass it any Graph endpoint, v1.0 or beta. You can find out what the endpoints are at the Graph Explorer.  Right now this only supports Gets. You’ll also have to manually put in any parameters or filters. I’ve added help and examples. I hope to expand them both in the future.

The output is a stand PSCustomObject, so you can send its output down the pipeline however you’d like. Select-Object, Where-Object, Sort-Object, the world is your oyster.

Let me know if this is useful and what you’re doing with it.

tk

ShortURL: https://www.toddklindt.com/PoshMSGraph

Comments

Bot blocker

Too bad the comment bots can't be blocked. ;(
 on 6/10/2022 3:16 PM

Microsoft

I was looking for types of referencing style and found a team of experts who helped me out and gave me quality work, their link is given below. PnP PowerShell is a . NET Core 3.1 / . NET Framework 4.6. 1 based PowerShell Module providing over 600 cmdlets that work with Microsoft 365 environments such as SharePoint Online, Microsoft Teams, Microsoft Project, Security & Compliance, Azure Active Directory, and more.
 on 7/8/2022 2:17 AM

Re: Calling Microsoft Graph with PnP PowerShell

It's great to see discussions about Microsoft Graph and M365 Admin tools! PowerShell can indeed be quite challenging. If you’re looking for a fun way to take a break from coding, I suggest trying the <a href="https://infinitecrafts.io">Infinite Craft</a> game. It’s a great way to clear your mind and come back to technical challenges refreshed. Also, have you explored any other community resources to enhance your Graph skills?

 on 12/23/2024 8:09 PM

Rene Ziemba

This is a great resource for working with Microsoft Graph using PnP.PowerShell! For those looking to expand their skills further, consider exploring fun coding challenges like the Slope Game—it's a fantastic way to practice logical thinking while reinforcing your coding abilities. https://slopegame.lol/
 on 12/24/2024 4:00 AM

slope game

Comment: This resource for Microsoft Graph and PnP.PowerShell is indeed valuable! To further enhance your skills, don't miss out on fun coding challenges like the Slope Game. It's an enjoyable way to sharpen your logical thinking and coding abilities while having a blast. Give it a try: https://slopegame-3d.com/

 on 1/2/2025 9:31 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit