Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Created April 30, 2018 22:14
Show Gist options
  • Save alexeldeib/eb78a553d6adb043e666e192e5c6abcb to your computer and use it in GitHub Desktop.
Save alexeldeib/eb78a553d6adb043e666e192e5c6abcb to your computer and use it in GitHub Desktop.
Log Analytics Powershell create saved search (new query language)
$SubscriptionId = "dcc1e4f0-f18b-405e-85d7-1bab42e085d0"
$ResourceGroupName = "demo-rg"
$Workspace = "ExampleWS"
$SavedSearchId = [string]"$(New-Guid)"
$Category = "Patching"
$DisplayName = "Computers missing KB3023219"
$Query = 'Update | where KBID == "3023219" and UpdateState == "Needed" | distinct Computer'
$Version = "1"
$ResourceId = "subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.OperationalInsights/workspaces/$Workspace/savedSearches/$SavedSearchId"
$Type = "Microsoft.OperationalInsights/workspaces/savedSearches"
$GroupProperties = [PSCustomObject]@{
Category=$Category
DisplayName=$DisplayName
Query=$Query
Version=$Version
}
New-AzureRmResource -ResourceId $ResourceId -Properties $GroupProperties -ApiVersion "2017-03-15-preview"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment