question

AbhishekSingh-7599 avatar image
0 Votes"
AbhishekSingh-7599 asked SathyamoorthyVijayakumar-MSFT edited

I want to query log analytics using managed identity of automation account runbook with powershell script not getting any samples for the same

I want to query log analytics using managed identity of automation account runbook with powershell script not getting any samples for the same ,
same way we have samples for virtual machine managed identity used for accessing keyvault in powershell script.

windows-server-powershellazure-monitorazure-automationazure-managed-identity
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SathyamoorthyVijayakumar-MSFT avatar image
1 Vote"
SathyamoorthyVijayakumar-MSFT answered SathyamoorthyVijayakumar-MSFT edited

You could make use the below snippet I spun to query the Log Analytics using the Managed Identity

I am making use of the below commandlet

Invoke-AzOperationalInsightsQuery

The commandlets needs Modules - Az.Accounts & Az.OperationalInsights

 param (
     [Parameter(Mandatory=$true)] 
     [String]  $WorkSpaceId,
     [Parameter(Mandatory=$true)] 
     [String]  $Query 
         
     )
 #$connectionName = "AzureRunAsConnection"
 try
 {
     # Logging in as Managed Identity
     "Logging in to Azure..."
      Connect-AzAccount -Identity
 }
 catch {
     "Error Occured while Authenticating"
 }
 "Executing the query"
 $result = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkSpaceId -Query $Query
 "Printing the results"
    
 $result.results

Output :

104773-image.png




image.png (18.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.