Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Last active July 9, 2018 20:25
Show Gist options
  • Save alexeldeib/b610c11346ce79fe62bf4e3b3e2c6d76 to your computer and use it in GitHub Desktop.
Save alexeldeib/b610c11346ce79fe62bf4e3b3e2c6d76 to your computer and use it in GitHub Desktop.
Azure Automation Log Analytics Query
workflow la-test
{
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$connectionName = "AzureRunAsConnection";
#Get the credential with the above name from the Automation Asset store
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName;
Write-Output $servicePrincipalConnection;
if(!$servicePrincipalConnection) {
Throw "Could not find an Automation Credentials. Make sure you have created an Automation Account."
}
#Connect to your Azure Account
Clear-AzureProfile -force
Connect-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint `
-ApplicationId $servicePrincipalConnection.ApplicationId `
Write-Output "Querying..."
$dynamicQuery = 'union * | take 10'
$Result = Invoke-AzureRmOperationalInsightsQuery -Debug`
-WorkspaceId "<GUID>" `
-Query $dynamicQuery
Write-Output $Result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment