Last active
July 9, 2018 20:25
-
-
Save alexeldeib/b610c11346ce79fe62bf4e3b3e2c6d76 to your computer and use it in GitHub Desktop.
Azure Automation Log Analytics Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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