This article covers Windows 10/11 Intune managed devices. To automate device wipe based on Last Checked-In Date and Device Scope Tag using Azure Automation Runbook and Azure Storage Blob for logging.

  • Login to Azure Portal with Administrative or equivalent rights
    Then click on the  “Automation Accounts
  • Click “Create” and enter appropriate information, then click “Review+Create

    Automation account name (example: IntuneDeviceLifeCycleManagement)
  • Go to the resource once created then click “Shared Resources -> Modules”
    Then browse and add the following modules (Runtime 5.1)

  • Under the “Account Settings” of the Automation Account click on “Identity” make a note of the “Object (principal) ID” then use the following PowerShell script to assign API Permissions.
    Prerequisites for PowerShell.
    Install-Module MSGraph

    Use Azure administrative or equivalent account to Authenticate when running the script.

Validate the permissions are assigned to the Managed Identity. From Entra ID portal select Enterprise Application then search by Object ID and view permission.

  • Create Azure Storage Account

    Click “Create” and enter the required information. Then click “Review+Create
  • Access the Storage Account and create a “+Container
  • Access the Container and click on “Access Control (IAM)
  • Assign permissions to the Container for Managed Identity Automation Account using “Object (principal) ID

    Storage Blob Data Contributor” and “Storage Blob Data Reader
  • From the Automation Account under Process Automation select Runbooks then “+Create a runbook
  • Select the following to create the Runbook then click “Review + Create
  • Use Edit in Portal option to copy the following script.
    Replace the following items with your environment values.
    •  $daysInactive = 10
    •  $targetScopeTagName
    •  $logFileName
    •  $emailRecipient
    •  $emailSender
    •  $smtpServer
    •  AUTOMATION-ACCOUNT-MANAGED-IDENTITY-OBJECT-ID
    •  $storageAccountName
    •  $containerName
    •  YOUR-STORAGE-CONNECTION-STRING

Validation

  • Click the “Test pane”
  • Click the “Start” button
  • Ensure the task is completed without any errors, similar to the example below then close the window “X” button.
  • Validate the storage container to ensure logs were generated

  • Click the “Publish” button, then click “Yes” button.