smsagent.blog
  • docs.smsagent.blog
  • Custom Reporting in Microsoft Intune
    • Delivery Optimization Report
    • Windows Update for Business Custom Reporting
      • Power BI Report Walkthrough
      • Known issues / limitations
      • Change log
      • Deploy the solution
        • Create Azure Resources
        • Configure Azure Resources
        • Deploy the client-side script
        • Deploy the Azure automation runbooks
        • Configure the Power BI report
      • Adding additional language support
      • Table schema reference
    • Automating Data Exports from Microsoft Graph
      • Azure Automation account
        • Create / configure an Azure automation account
        • Grant API permissions
        • Create an Azure automation runbook
      • Azure Storage account
      • Automate Data Export to Azure Storage Account
      • Automate Data Export to Azure Monitor Logs
      • Creating / Troubleshooting Runbooks
      • Power BI
        • Connect Power BI to an Azure storage account data source
        • Connect Power BI to an Azure log analytics workspace as a data source
    • Managed Devices Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a PowerBI report
      • MEM Managed Device Report template
      • Bonus! Unhealthy MEMCM Clients email report
    • Intune Assignments Report
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create a Power BI report
      • Change log
    • Patch My PC Report
      • A look at the Power BI reports
      • Change log
      • Video guides
      • Things to know
      • Create / configure an Azure automation account
      • Grant API permissions
      • Create / configure an Azure storage account
      • Create an Azure automation runbook
      • Create the Power BI report
      • Feedback
    • Windows 11 Hardware Readiness Report
    • Gathering Custom Inventory with Intune
      • Set up the Azure Resources
      • Create a Proactive remediations script package
      • Create a runbook
  • PowerShell Scripts Online Help
    • Get-AzSubscriptionActivityLog
  • Azure Solutions
    • Automated Azure Table Storage Backups
      • Change log
      • Deploy the solution
        • Create the Azure resources
        • Set the backup schedule
        • Add storage tables to the backup
        • Add role assignments to the storage account/s
        • Create a lifecycle management rule
      • Run a manual backup
      • Restore a backup
Powered by GitBook
On this page
  • Developing locally
  • Logging output

Was this helpful?

  1. Custom Reporting in Microsoft Intune
  2. Automating Data Exports from Microsoft Graph

Creating / Troubleshooting Runbooks

Developing locally

You can develop and debug an Azure automation runbook locally using Visual Studio Code, for example. To customize or troubleshoot the runbooks provided in this guide, change the Authentication section of the PowerShell script to authorise your own user account instead of as a managed identity or runas account. This assumes that your user account has at least the same permissions that you have granted to the managed identity of your automation account.

In the Authentication section of the script, simply replace the existing code with the following as an example. Make sure the accessToken variable is set to the script scope so it can be used within the functions.

####################
## AUTHENTICATION ##
####################
# To authenticate with Microsoft Graph:
# Install-Module Microsoft.Graph.Intune -Force
$script:accessToken = Connect-MSGraph -PassThru
# If you need to access the Azure storage account:
# Install-Module Az.Accounts -Force
# Install-Module Az.Storage -Force
$null = Connect-AzAccount # Optional: -Subscription "<my-subscription>" -Tenant "<my-tenant-id>"

Once you have developed or finished debugging your script, simply change the Authentication section back to the original code and update the runbook in the automation account.

Logging output

While you are developing or testing your script locally, you can use, for example, Write-Host, Write-Output, Write-Warning, Write-Verbose to return output to the PowerShell host.

When executing the runbook, however, you can't use Write-Host. You can use Write-Output but the recommended way is to use Write-Verbose and set the $VerbosePreference variable to Continue so that the output will display.

Bear in mind that using Write-Output inside a function that returns to a variable will send the output to that variable and not to the output stream.

More details on using output in a runbook and general troubleshooting advice can be found in the articles below.

PreviousAutomate Data Export to Azure Monitor LogsNextPower BI

Last updated 3 years ago

Was this helpful?

Runbook Output and Messagesdocsmsft
Logo
Troubleshoot Azure Automation runbook issuesdocsmsft
Logo