title: To create the Log Analytics alerts using Azure Power Shell or Azure CLI
body: <p>I'm trying to create alerts in LogAnlytics in azure portal, need to create 6 alerts for 5 db's, so have to create 30 alerts manually and is time consuming.</p>
  
  <p>Hence would require an automated approach.</p>
  
  <p>Tried to create via <a href="http://%20https://www.c-sharpcorner.com/article/creating-alerts-using-azure-powershell/" rel="nofollow noreferrer">Creating Alerts Using Azure PowerShell</a>,  but this creates the alerts in the Alerts Classic under Monitor but this is not what is required, require it to be created in Log Analytics.</p>
  
  <p>Next approach was via <a href="https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-create-metric-alerts-with-templates" rel="nofollow noreferrer">Create a metric alert with a Resource Manager template</a> but this was metric alert and not LogAnalytics alert</p>
  
  <p>At last tried <a href="https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-api-alerts" rel="nofollow noreferrer">Create and manage alert rules in Log Analytics with REST API</a>, but this is a tedious process need to get the search id, schedule id, threshold id and action id. Even after trying to create the threshold id or action id the error I'm facing is "404 - File or directory not found." (as in the image).</p>
  
  <p><a href="https://i.stack.imgur.com/D29TL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D29TL.jpg" alt="Error"></a></p>
  
  <p><strong>Could someone please suggest me on how should this be proceeded, or is there any other way to create alerts apart from the manual creation?</strong></p>