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.
3,210 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,242 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,511 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,425 questions
0 comments No comments
{count} votes

Accepted answer
  1. svijay-MSFT 5,226 Reputation points Microsoft Employee
    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 Answers by the question author, which helps users to know the answer solved the author's problem.