Get-OMSsearchQueryResults.ps1
<#PSScriptInfo .VERSION 1.1 .GUID 371649a1-3119-4ebd-a1a8-7150b132d18b .AUTHOR Tiander Turpijn .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION OMS Search API Azure Automation sample runbook using native PowerShell cmdlets TODO: $dynamicQuery - Enter your custom query here StartDateAndTime - Provide your start date and time EndDateAndTime - Provide your end date and time AutomationCredentialAssetName - Provide the name for your Azure Active Directory account ResourceGroupName - Provide the resource group name of your OMS workspace name WorkSpaceName - Provide your workspace name #> param ( [Parameter(Mandatory=$false)] [string]$dynamicQuery = "* | Measure count() by Type", [ValidateNotNullOrEmpty()] [string]$StartDateAndTime = "2016-03-10T18:20:58.8Z", [ValidateNotNullOrEmpty()] [string]$EndDateAndTime = "2016-03-10T18:30:58.8Z" ) #Get Azure Active Directory account with access to my Azure subscription $AutomationCredentialAssetName = "YOUR_CREDENTIAL_HERE" $Cred = Get-AutomationPSCredential -Name $AutomationCredentialAssetName #Get Workspacename and resource group name $WorkSpaceName =Get-AutomationVariable -Name 'WorkSpaceName' $ResourceGroupName = Get-AutomationVariable -Name 'ResourceGroupName' # Authenticate to Azure Resource Manager "Authenticating...." Add-AzureRmAccount -Credential $Cred | out-null #Execute a dynamic query and output the results Write-Output ("Executing the following query: $dynamicQuery") $result = Get-AzureRmOperationalInsightsSearchResults -ResourceGroupName $ResourceGroupName -WorkspaceName $WorkSpaceName ` -Query $dynamicQuery -Start $StartDateAndTime -End $EndDateAndTime "`n" Write-Output "Query results:" $result.Value |