Permissions to query Azure Log Analytics from PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1530601%22%20slang%3D%22en-US%22%3EPermissions%20to%20query%20Azure%20Log%20Analytics%20from%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1530601%22%20slang%3D%22en-US%22%3E%3CP%3ETeam%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20able%20to%20query%20with%20the%20following%20Code%20from%20one%20Work-space%20but%20same%20code%20is%20not%20working%20for%20another%26nbsp%3BWork-space%20but%20I%20am%20able%20to%20query%20directly%20after%20login%20both%20the%20workspace%20.%20I%20have%20read%20access%20where%20Powershell%20code%20does%20not%20returns%20any%20output.%20Do%20I%20need%20any%20additional%20permission%20to%20run%20the%20below%20Code%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24query%20%3D%20%22Heartbeat%20%7C%20where%20TimeGenerated%20%26gt%3B%20ago(1d)%20%7C%20summarize%20LastHeartbeat%20%3D%20max(TimeGenerated)%20by%20Computer%20%7C%20where%20isnotempty(Computer)%20%7C%20where%20LastHeartbeat%20%26lt%3B%20ago(1h)%22%20%0A%24selectSub%20%3D%20Set-AzContext%20-SubscriptionId%20%22f8878fbq-4ch3-4ce0-8b08-9729ab66fa42%22%0Aif%20(%24selectSub)%20%7B%20%20%20%20%0A%20%20%20%20%24Workspace%20%3D%20Get-AzOperationalInsightsWorkspace%20-Name%20%22insight-lt-workspace%22%20-ResourceGroupName%20%22azure-insight-lt%22%0A%20%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%24Result%20%3D%20Invoke-AzOperationalInsightsQuery%20-WorkspaceId%20%24Workspace.CustomerId.Guid%20-Query%20%24query%20-Verbose%20-ErrorAction%20SilentlyContinue%0A%20%20%20%20%7D%0A%20%20%20%20catch%20%7B%0A%20%20%20%20%20%20%20%20Write-host%20'Failure'%0A%20%20%20%20%7D%0A%7D%0A%20%0A%24Result.Results%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EBiswajit%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1530601%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowershell%20and%20Rest%20API%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Team,

 

I am able to query with the following Code from one Work-space but same code is not working for another Work-space but I am able to query directly after login both the workspace . I have read access where Powershell code does not returns any output. Do I need any additional permission to run the below Code ?

 

$query = "Heartbeat | where TimeGenerated > ago(1d) | summarize LastHeartbeat = max(TimeGenerated) by Computer | where isnotempty(Computer) | where LastHeartbeat < ago(1h)" 
$selectSub = Set-AzContext -SubscriptionId "f8878fbq-4ch3-4ce0-8b08-9729ab66fa42"
if ($selectSub) {    
    $Workspace = Get-AzOperationalInsightsWorkspace -Name "insight-lt-workspace" -ResourceGroupName "azure-insight-lt"
 
    try {
        $Result = Invoke-AzOperationalInsightsQuery -WorkspaceId $Workspace.CustomerId.Guid -Query $query -Verbose -ErrorAction SilentlyContinue
    }
    catch {
        Write-host 'Failure'
    }
}
 
$Result.Results

 

 

Thanks

Biswajit  

0 Replies