Microsoft Graph Explorer contains a hidden gem: code snippets.
Microsoft Graph Explorer PowerShell code snippets help you quickly adopt the Graph API. Let’s look at how you can generate PowerShell code in Microsoft Graph Explorer.
Nowadays, administrators are working more frequently with cloud platforms and difficult APIs to retrieve information. For PowerShell administrators, the change from commands like Get-User to REST APIs, bearer tokens, and HTTP requests represents a major initial challenge.
Graph Explorer can show you a successful REST call and its data, but figuring out the PowerShell code to do the same thing takes extra effort. That’s where code snippets come in.
In early 2022, Microsoft introduced a feature to Graph Explorer called code snippets. Code snippets auto-generate working code in multiple programming languages based on the Graph API query you just executed – including:
When you run a query like retrieving all users with specific properties, Graph Explorer not only shows you the JSON response but also provides the exact Get-MgUser command with all the correct parameters you’d need in your PowerShell script.
Getting started with PowerShell snippets in Graph Explorer is straightforward once you know where to look.
Although you can use Graph Explorer without logging in, signing in with your work account will give you a much better experience by letting you access your tenant’s real data. The sample data is often too limited to provide useful results and will produce generic responses.
The best way to understand the value of PowerShell snippets is to see them in action. You don’t need to know how to write complex REST API calls; Graph Explorer provides dozens of sample queries to get you started.

In the screenshot above, you can see the actual data returned from the query.

The magic here is that if you didn’t know how to search for all users, you could browse the various APIs in the Graph Explorer, pick one to run and then you can see the relevant PowerShell module and cmdlets that were used to retrieve the data.
This is the real value of PowerShell snippets: you can explore real tenant data through the web interface and immediately see the equivalent PowerShell commands needed to replicate those results in your own scripts.
Let’s try a more complex example that shows multiple Graph API features working together.

Get-MgUser -Filter “department eq ‘Finance’” -Sort “displayName” -Top 20 -CountVariable CountVar.
This single query teaches you several important PowerShell techniques: filtering by department, sorting results, limiting the number of results returned, and getting a count of total matches.

You can easily change this example to fit your specific needs. Go to the address bar in the Graph Explorer and change ‘Finance’ to any department that exists in your organization – ‘IT’, ‘Marketing’, ‘Sales’, ‘HR’, or whatever departments you have. You could also change the sorting from displayName to mail or jobTitle depending on how you want the results organized.
This flexibility makes the sample queries a powerful starting point for building your own custom administrative scripts.
Until now, we’ve performed GET operations to retrieve data; these are safe, read-only and don’t change your org. Let’s explore POST operations, which actually create or change resources in your tenant. This is where Graph Explorer’s power becomes apparent, but it’s also where you need to exercise caution.
When you run a POST operation to create a group, user, or any other resource, you’re changing your Microsoft 365 environment, and those changes will persist until you manually remove them.
Let’s create a new security group.
{
"displayName": "Test Security Group 26",
"mailEnabled": false,
"mailNickname": "testgroup26",
"securityEnabled": true,
"groupTypes": []
}

If you look at the Code snippets section, you’ll find that a PowerShell snippet is missing. Unfortunately, as mentioned earlier, while PowerShell snippets have good coverage for common GET operations (retrieving data), many POST, PATCH, and DELETE operations don’t yet have snippet support. The coverage varies for each API.
For these situations, you’ll need to refer to the Microsoft Graph PowerShell SDK documentation to find the equivalent cmdlet – in this case, New-MgGroup.
Let’s clean up the group we just created and see if DELETE operations have better PowerShell snippet support.
Note: The group ID shown here (498c8fb8-2b20-4a14-ad0f-535f6c37cf01) is unique to the group I created for this example. Your group will have a different ID that was generated when you created it. You can find your group’s ID from the response you received when creating the group, or by running a query to list groups and finding yours by name.

In this code snippet, Microsoft replaced the group ID with a variable called $GroupId. You could replace that variable with the actual group ID, and it would execute exactly the same.
In the last two examples, you can see that PowerShell snippets aren’t always present: there are no snippets for POST operations that create groups, but there are snippets for DELETE operations that remove them.
There’s no obvious pattern that reveals which operations have PowerShell snippet support and which don’t. When code snippets are unavailable, the SDK documentation should be your go-to resource or fall back to using direct REST API calls with Invoke-RestMethod in your PowerShell scripts.
The Graph Explorer’s history feature logs your queries for the past month. You’ll find this handy when you’re experimenting with different API calls, or if you want to repeat a past query and can’t be sure of the syntax you used.
This is especially valuable when you’re developing complex queries – you can experiment with different parameters, then easily return to a working baseline if your modifications don’t produce the expected results.

The history feature also serves as a learning log. After a session of exploring different APIs, you can review your history and literally replay your steps to see the progression of queries you tried and the PowerShell snippets they generated. This is very useful for documenting your successful executions or for sharing with team members.
As you explore different Graph APIs and their PowerShell snippets, you may encounter permission errors when trying to run certain queries. Even though you may have permission to perform an operation, Azure also requires user consent for some operations.
When you encounter a permission error, Graph Explorer will typically prompt you to consent to additional permissions needed for that specific operation. You might see a pop-up asking you to grant permissions like “User.Read.All” for reading user information or “Group.ReadWrite.All” for managing groups.
These permission prompts are normal and necessary for Graph Explorer to access different data on your behalf. However, it’s important to remember that you should completely understand the permissions you’re granting to prevent errors that could lead to data loss or provide excessive access for everyday activities.
To learn more about Microsoft Graph permissions, refer to the Microsoft’s Overview of Microsoft Graph permissions. If you need admin-level consent for certain operations, see the documentation on Granting tenant-wide admin consent to an application.
PowerShell snippets are very helpful, but it’s not all puppies and rainbows, at least not yet. PowerShell code snippets are not available for every Graph API. Remember that Microsoft Graph is a collection of hundreds of APIs created and maintained by different teams inside Microsoft, which means features don’t appear in Graph Explorer all at once.
But the good news is that the strongest PowerShell snippet coverage exists in the areas where administrators spend most of their time: user management, group operations, and basic organizational directory tasks. You’ll find that queries for retrieving user profiles, filtering users by specific attributes, managing group memberships, and performing common Exchange Online mailbox operations typically generate clean, working PowerShell code.
However, as you venture into more specialized APIs that touch on newer features, advanced security configurations, or complex multi-step workflows, you may encounter operations that don’t yet have PowerShell snippet support. Areas like advanced compliance policies, detailed SharePoint site provisioning, complex Teams governance settings, and some of the newer security APIs may show the REST API call working perfectly in Graph Explorer but provide no corresponding PowerShell code snippet.
In these cases, you’ll need to translate the successful REST call into PowerShell using the Microsoft Graph SDK documentation, or fall back to using direct REST API calls with Invoke-RestMethod in your PowerShell scripts.
Graph Explorer is a tool to help navigate the complexities that come with using the Microsoft Graph API. Explorer is a web-based tool that allows you to test and experiment with Microsoft Graph API calls without having to write code. Think of it as a front-end UI for the Microsoft Graph API. The Graph Explorer lets you browse available API endpoints, run queries against live data, and see the results in real-time.
The Microsoft Graph API is the primary interface for accessing data and intelligence in Azure, Microsoft 365, SharePoint, and similar products programmatically. Through Microsoft Graph, you can access data and intelligence living in Microsoft’s cloud services. Think of Graph as the fabric that connects all Microsoft services together.
Graph Explorer bridges the gap between traditional PowerShell administration and modern Graph-based automation. Instead of struggling to translate REST API documentation into working PowerShell, you can test queries against real data and get the code snippets immediately.
This overview covers just the basics of the Microsoft Graph Explorer’s PowerShell snippets feature. We’ve looked at how to find and run sample queries, generate PowerShell code from your results, and work around the gaps where snippets aren’t available yet. Practice with different sample queries, experiment with various workloads, and explore the PowerShell snippets they generate. With regular use, it’ll become an essential part of your admin toolkit.
No, Microsoft Graph will not replace PowerShell. Instead, Microsoft is gradually moving functionality that traditionally required PowerShell modules (like Azure AD and MSOnline) into Microsoft Graph APIs. The newer Microsoft Graph PowerShell SDK allows you to use PowerShell while leveraging Microsoft Graph under the hood.
Microsoft Graph Explorer is a web-based tool provided by Microsoft that lets you run queries against Microsoft Graph without writing code. To use it:
This tool is mainly for testing queries before implementing them in PowerShell, apps, or automation scripts.
Yes, Microsoft Graph is free to use, but with conditions:
Alternatives depend on the scenario:
Ultimately, Microsoft Graph is becoming the single unified API, so while alternatives exist, they’re being phased out.