Azure Resource Grah Explorer query CSV results automation

SPK545 16 Reputation points
2020-12-07T23:44:20.18+00:00

hello,

I have recently picked up a use case as follows,

1) I need to run a query from the Azure Resource graph and export those results on daily basis to the Azure database

2) I'm currently running query (KQL to know about resources in Azure) and exporting into CSV file, sending them manually

how I can achieve this automatically where my query runs a daily basis and send that CSV file to Database?

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,285 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2020-12-09T12:47:41.953+00:00

    Hi @SPK545 ,

    AFAIK you should be able to achieve it with the help of Az PowerShell cmdlet Search-AzGraph or Az CLI command az graph query or Az REST API Resources - Query and then exporting the output and sending it to a destination or (to a database as in your case).

    For example, below is the Az PowerShell command to export all resources details.

    Search-AzGraph -Query "Resources" -first 1000 | epcsv .\testgraph.csv -NoType  
    

    Note that, by default this procedure returns only 100 records but it can return maximum up to 5000 records so with the help of -First parameter you may explicitly mention the number of records that you wanted to return.

    Along with it, you may come up with code snippet to send the output to required destination (say database) and schedule it to run on daily basis by saving the complete code as script in a Azure Automation runbook or Azure Logic App, etc.

    On the other hand as shown in below screenshot, portal way provides options to download the csv and pin to dashboard but not an option to export data to external sources like PowerBI, EventHub, DB, etc. so if interested, you may raise a feature request for it here. In general, Azure feature or product team would check feasibility of a feature request, prioritize against existing feature backlog, add in roadmap as appropriate and would announce and/or update the related Azure document once a feature request is addressed.

    46623-image.png

    0 comments No comments

  2. SPK545 16 Reputation points
    2020-12-09T15:58:59.96+00:00

    Thanks, @tbgangav-MSFT ,

    In fact46643-flow1.jpeg46721-error.jpeg, I'm trying to use a graphical runbook (don't know much about Powershell) to automate this process and designed a flow as well, I am getting an error, not sure what I'm missing here

    0 comments No comments