Create Direct Link to a Log Analytics Query | Quisitive
Create Direct Link to a Log Analytics Query
October 22, 2018
Matthew Dowst
All you need to get started is a Log Analytics Workspace and a little bit of PowerShell.

This post will show you how you can create a URL to a specific Log Analytics query.

When navigated to, this URL will automatically open the Log Analytics Query editor, input your query, and execute it. This URL can be embedded in your custom alerting solutions, used to create a bookmark for queries, or anything else you can think of. All you need to get started is a Log Analytics Workspace and a little bit of PowerShell.

The PowerShell functions you need can be downloaded from my GitHub Gist. To execute it you need to get your Log Analytics Workspace name and the Subscription GUID and Resource Group that contains your workspace. To find these values, you can navigate to your Log Analytics Workspace in the Azure Portal, and copy then from the Overview blade.

Log analytics query

Once you have this information you simply need to call the Write-LogAnalyticsURL function to create your link. I have provided a couple of examples below.

123456789# Create URL that you can change the computer name on$ComputerName = ‘SEVER01.BLOG.DEMO’$queryString = @”Heartbeat| where TimeGenerated >= ago(1h)| where Computer == “$ComputerName””@$URL = Write-LogAnalyticsURL -SubscriptionId $SubscriptionId -ResourceGroup $ResourceGroup -Workspace $Workspace -QueryString $QueryString
12345678910111213# Create URL and Open it in Your default browser$queryString = @’Usage | where TimeGenerated > ago(3h)| where DataType == “Perf” | where QuantityUnit == “MBytes” | summarize avg(Quantity) by Computer| sort by avg_Quantity desc nulls last| render barchart’@$URL = Write-LogAnalyticsURL -SubscriptionId $SubscriptionId -ResourceGroup $ResourceGroup -Workspace $Workspace -QueryString $QueryString[System.Diagnostics.Process]::Start($URL) | Out-Null

The most recent version of this script, and many more scripts are available on my GitHub Gist. For more info, please contact us.