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

Abhishek Singh 381 Reputation points
2021-06-09T16:24:55.89+00:00

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.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Answer accepted by question author
  1. svijay-MSFT 5,256 Reputation points Microsoft Employee Moderator
    2021-06-11T10:14:59.9+00:00

    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

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.