Exporting results from Azure CLI to my environment

Ricardo Anselmo Oliveira 101 Reputation points
2021-12-31T15:48:24.567+00:00

Hi, i would like to know if it is possible and how to export a result set from Azure CLI to my computer environement.
So , the result set is coming from a query i run against a workspace on Azure Log Analytics, i get the results nice in the CLI/POWERSHELL(--output tsv), but when i use export, the file i specified it didn't bring the results.

Command im using:

az monitor log-analytics query -w 1f(...) --analytics-query "let top5Containers= KubePodInventory |extend MyName = tostring(split(ContainerName,'/')[1]) |extend InstanceName=strcat(ClusterId,'/',PodUid,'/',MyName) (...) ;" --output tsv | Export-Csv -Path "C:...test.csv"

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,658 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.5K Reputation points MVP Volunteer Moderator
    2021-12-31T16:29:23.71+00:00

    Hi @RicardoAnselmoOliveira-7430 ,

    where are you executing the Azure CLI? In the portal or on your computer?

    Not sure if it's just a typo: --output tsv | Export-Csv -Path "C:...test.csv"
    If you choose tsv format for output you can't export this with Export-Csv

    Does this work?

    az monitor log-analytics query -w 1f(...) --analytics-query "let top5Containers= KubePodInventory |extend MyName = tostring(split(ContainerName,'/')[1]) |extend InstanceName=strcat(ClusterId,'/',PodUid,'/',MyName) (...) ;" --output tsv >"C:...test.tsv"   
    

    Another option might be:

    az monitor log-analytics query -w 1f(...) --analytics-query "let top5Containers= KubePodInventory |extend MyName = tostring(split(ContainerName,'/')[1]) |extend InstanceName=strcat(ClusterId,'/',PodUid,'/',MyName) (...) ;" --output tsv | Export-Csv -Path "C:...test.csv" -Delimiter "`t"   
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ricardo Anselmo Oliveira 101 Reputation points
    2021-12-31T16:49:49.01+00:00

    hello! TY for your response!

    It worked with the tip ">"C:...Test.tsv" !!!

    But now i have another question:How can i add a Delimiter to separate the results, so i can paste it after in the excel? (if it's possible)

    TY SO MUCH @Andreas Baumgarten

    UPDATE: Nevermind, it already come delimited with SPACE.

    0 comments No comments

  2. Andreas Baumgarten 123.5K Reputation points MVP Volunteer Moderator
    2021-12-31T16:58:20.793+00:00

    Hi @RicardoAnselmoOliveira-7430 ,

    how does the tsv file looks like. I would like just to see the formatting of the content. Maybe from there it's possible to convert to csv or maybe even open the tsv file in Excel.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


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.