# Create an Azure automation runbook

## Video guide

Here is a video guide which I created for the Patch My PC report which covers the steps outlined below.

{% embed url="<https://youtu.be/HswgdFVzDPw>" %}

## Import Modules

If you wish to export data to an Azure storage account, you will need a couple of PowerShell modules added to the automation account for the runbook to use.

* In the Azure portal in the automation account, go to the **Modules gallery** pane
* Search for and import the following modules:
  * **Az.Accounts**
  * **Az.Storage**

## Create a Runbook

* Click on the **Runbooks** pane and choose **Create a runbook**
* Enter a name for the runbook, select **PowerShell** for the runbook type and click **Create**
* Here you can enter your PowerShell code. To get started, check out the included examples for [exporting to an Azure storage account](https://docs.smsagent.blog/microsoft-endpoint-manager-reporting/automating-data-exports-from-microsoft-graph/automate-data-export-to-azure-storage-account) and [exporting to a Log analytics workspace](https://docs.smsagent.blog/microsoft-endpoint-manager-reporting/automating-data-exports-from-microsoft-graph/automate-data-export-to-azure-monitor-logs).
  * If you wish to test the runbook before publishing to make sure it works, use the **Test pane**
  * Alternatively, **Publish** the runbook, then click **Start** from the runbook menu. This option will give you the full output of the script.
* When ready, **Publish** the runbook

## Schedule the Runbook

Schedule the Runbook to execute at regular intervals to keep the data updated.

* In the Azure portal, in the automation account, open the Runbook you created
* Click **Link to schedule**
* In the **Schedule** section, select an existing schedule or create a new one

![](https://3886807721-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWe9ieepRHnj7T8odXt%2F-M_RvziJmG2w3VdEaGV-%2F-M_SHJw26sAMuYhaSEaI%2Fimage.png?alt=media\&token=d8396286-515a-47c9-a1bf-32069484ebb9)
