Blog Post

ITOps Talk Blog
2 MIN READ

How to Share Azure Resource Graph Queries as a Link

thomasmaurer's avatar
thomasmaurer
Icon for Microsoft rankMicrosoft
Jun 24, 2020

Azure Resource Graph is a service in Azure that allows you to performant resource exploration with the ability to query at scale across a given set of subscriptions so that you can effectively govern your environment. You can get an overview of the resources in different subscriptions, and you can even generate charts. You can run these queries from Azure PowerShell or Azure CLI, or to get a view of these queries, you can use Azure Resource Graph Explorer in the Portal.

 

Azure Resource Graph Explorer Chart

As an example, I used Azure Resource Graph queries, to list the agent version of Azure Arc enabled servers.

To share these queries with others, you have a couple of options. You can share it directly within the Azure portal. 

 

Save Shared Azure Resource Graph Query

Create an Azure Resource Graph Explorer Query Link

 

But thanks to David Coulter (Microsoft), I learned that you also can simple create URLs, including the Azure Resource Graph query. This is great if you simply create a link and will automatically copy the query to the Azure Resource Graph Explorer.

 

You can do this by using the following URL and append the URL encoded query to the URL.

 

Query URL:

 

 

https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/

 

 

 

Azure Resource Graph Query:

 

 

Resources| summarize count()

 

 

 

URL encoded Query:

 

 

Resources%7C%20summarize%20count()

 

 

 

To URL encode, you can use a website like Code Beautify or the following Visual Studio Code extension.

 

Complete Azure Resource Graph URL:

 

 

https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%0D%0A%7C%20summarize%20count%28%29

 

 

 

So if you click on the following link, it will automatically open the Azure Portal with the above Azure Resource Graph Query: 

 

Azure Resource Graph Explorer Query using a Link

 

Conclusion

Thanks again to David Coulter or the tip. I hope this gives you an overview of how you can share the Azure Resource Graph Query using a simple link. If you have any questions, feel free to leave a comment.

To learn more about how to create Azure Resource Graph Queries, check out Microsoft Docs: Starter Resource Graph query samples

Updated Jun 24, 2020
Version 2.0
  • ewscorteva's avatar
    ewscorteva
    Copper Contributor

    This is amazing, but if you regularly leave yourself comments in your code (with //) you *may* need to remove them BEFORE URL-encoding. Otherwise instead of your nice set of columns and sorting your recipient gets only the portion of the query that happens before the first //, because the URL-encoding doesn't preserve newline characters (at least the VSCode plugin didn't) so the Resources.... query ends up on one line, and the // means it ignores everything after those characters.

     

    It appears urlencoder.io preserves the newlines with %0A so hats off to them, that should help with keeping comments in place (like a commented line or an end of line comment). I tested with the plugin first so ran into this weird issue, and then tested with the site which keeps things much more consistent with how they would appear if you saved and shared the query in the portal.

  • AnotherHowie's avatar
    AnotherHowie
    Copper Contributor

    This is really neat, but it'd be even nicer if I could link to the RESULTS page and save having to explain "click Run to see the results"