# Create a runbook

Create an Azure automation runbook that will export your inventory data from Microsoft Graph.

## Get your Proactive remediations script package GUID

For the automation runbook, we'll need to know the GUID of the script package we just created. An easy way to do this is to use the Developer Tools in Microsoft Edge.

In the MEM portal, navigate to Proactive remediations, but before you click on the script package you created, press F12 to open the DevTools. Click on the **Network** tab at the top.

Then click to open the script package and you'll see the URL/s that the portal is calling. You'll see one with the name **getRemediationHistory**, for example - right-click on that and copy the link address.

![](/files/-Mj_HDNRaJYlze9BZCpj)

![](/files/-Mj_HpId4Zc5MUM948qp)

You can then paste it into notepad, for example, and you'll have the GUID that you need in the URL. Make a note of this GUID.

![](/files/-Mj_I1MeKDFA3tsLkKsS)

## Create a runbook (sending to Azure storage account)

Download the following runbooks script.

{% embed url="<https://github.com/SMSAgentSoftware/MEM/blob/main/%5BReporting%5D%20SoftwareUpdates/Export-MSGraphInventoryData-SoftwareUpdates.ps1>" %}

In your Azure automation account, navigate to **Runbooks** and Import a runbook. Browse to and import the runbook script, select the Runbook type **PowerShell** and add a description.

![](/files/-MjeOyC8P9JKtyCdg08u)

In the runbook script you'll need to add some parameter values at the top:

* **$ResourceGroup.** This is the name of the resource group that your storage account belongs to.
* **$StorageAccount**. This is the name of your storage account.
* **$Container**. This is the name of the container in the storage account where you'll export your data to (must exist)
* **$ProactiveRemediationsScriptGUID**. This is the GUID for your PR script package that you obtained earlier.

The rest of the script can remain unchanged.

![](/files/-MjeO0UhCHsRUZ6QS8Ld)

**Publish** the runbook, then start it. After execution is complete, you should see the CSV file created in your storage account.

![](/files/-MjeO7Tve-8izVI0pPiF)

On the **Edit** tab of the blob, you can see your exported data.

![](/files/-MjeOFROJPY2Gj6WuCzC)

For completeness, here's the same data imported into Power BI.

![](/files/-MjeOKXkmljqBpQnEpBL)

## Create a runbook (sending to Log Analytics workspace)

First you'll need to add the **WorkspaceID** and **PrimaryKey** from the Log Analytics workspace as encrypted variables in the Azure automation account.

In your LA workspace, go to **Agents management** and copy the Workspace ID and Primary key.

![](/files/-MjeUb2jMvKc7-lsSk-m)

In the automation account, go to **Variables** and **Add a variable**.

Create the following variables as strings and paste in the copied values. Select the **Encryption** option.

* **WorkspaceID**
* **PrimaryKey**

![](/files/-MjeVgoaaj8NDkOElYZn)

Now download the following runbook script.

{% embed url="<https://github.com/SMSAgentSoftware/MEM/blob/main/%5BReporting%5D%20SoftwareUpdates/Export-MSGraphInventoryData-SoftwareUpdates_LA.ps1>" %}

In your Azure automation account, navigate to **Runbooks** and Import a runbook. Browse to and import the runbook script, select the Runbook type **PowerShell** and add a description.

![](/files/-MjeOyC8P9JKtyCdg08u)

In the runbook script you'll need to add some parameter values at the top:

* **$ProactiveRemediationsScriptGUID**. This is the GUID for your PR script package that you obtained earlier.
* **$LogName**. This is the name of the custom log you'll send data to in the LA workspace. It doesn't need to already exist.

As long as your automation account variables are named the same as in the script, you don't need to change those.

![](/files/-MjeZ19vGojeG-bHYJd2)

The rest of the script can remain unchanged.

**Publish** the runbook, then start it. After execution is complete, you can query the data in the custom log from the LA workspace. Bear in mind that for the first run it can take some minutes before the data is ingested and available in the workspace.

The custom log name will be appended with "\_CL" and only non-null values will be ingested and available to report on.

![](/files/-Mje_VIk889lplbn2jm3)

## Schedule the runbook

Schedule the Runbook to execute at the desired 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

![](/files/-Mdb-dKf7HOTU8cF6bcx)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.smsagent.blog/microsoft-endpoint-manager-reporting/gathering-custom-inventory-with-intune/create-a-runbook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
