Integrate Azure Powershell result into Azure workbook

William Li 0 Reputation points
2023-05-22T23:21:41.7833333+00:00

I want to grab the PITR and longTermRetentionWeeks for all the sql databases in azure and display this along with some other basic values in azure workbook(for example subscription name, resource group name, db name, PITR, etc).

Seems these 2 values are not supported in resource graph query, I can get these through azure powershell(using

Get-AzSqlDatabaseBackupShortTermRetentionPolicy

), but seems Azure powershell is not supported in azure workbooks.

Any way I can achieve this?

Azure SQL Database
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,321 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AirGordon 7,030 Reputation points
    2023-05-23T07:01:11.5933333+00:00

    You could use the Search-AzGraph cmdlet to access the Resource Graph query results from PowerShell. This would give you the ability to either augment the query with the results from Get-AzSqlDatabaseBackupShortTermRetentionPolicy, or to use the results from the query when calling the Get-AzSqlDatabaseBackupShortTermRetentionPolicy cmdlet.

    https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-powershell#run-your-first-resource-graph-query

    Executing the PowerShell could then be done locally, from an Azure Automation Account Runbook, or another service capable of running PowerShell.


  2. Limitless Technology 44,116 Reputation points
    2023-05-23T09:43:03.0633333+00:00

    Hello there,

    When a runbook function writes to the output stream, the output is passed back to the runbook. If the runbook assigns that output to a variable, the output is not written to the output stream. Writing to any other streams from within the function writes to the corresponding stream for the runbook.

    Azure Automation works with each of these streams differently. You should follow best practices for using the streams when you're creating a runbook.

    https://learn.microsoft.com/en-us/azure/automation/automation-runbook-output-and-messages

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--