Skip to content
Menu

Intune Remediation - Create the Detection and Remediation Pair

Stage two approved scripts for a client’s Intune change. In Windows PowerShell 5.1, a dry-run row can show “Would change”. Check the package name against the change ticket before creating it.

Intune remediation - create the detection and remediation pair is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Intune remediation - create the detection and remediation pair. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: DeviceManagementScripts.ReadWrite.All (beta); an Intune license
Changes thingsChanges what it runs on

What It Does

This script reads two PowerShell files from this computer, the detection script and the remediation script, and creates one Proactive Remediation in the tenant's Intune. Graph calls it a device health script. Each file must exist, must not be empty and must be at most 2 MB. It never deletes a remediation.

It does not assign. A remediation created here runs on no device: the code reaches devices only when you assign it to a group or filter and give it a schedule in the Intune admin center. There is no schedule input, because a remediation's schedule belongs to its assignment. That is why the script is Low risk.

It matches non-global remediations by display name. If two or more match, it stops and asks you to rename or delete the duplicates. If the package already holds these two scripts, it leaves the scripts and settings alone. When a matching package has different scripts, replacing it requires Update=true. With Update=true and different scripts it replaces the scripts and settings, keeps the assignments, and first saves the old remediation, scripts included, as a JSON file under the MSPOutpost data folder, named in the output.

After saving, it reads the remediation back and checks the name. Microsoft publishes this feature only in Graph beta and says beta calls can change, so every call here is beta.

For a fictional package named Printer defaults, a dry-run row would show Item “Printer defaults”, Change “Create the Intune remediation (not assigned to anyone)” and Result “Would change”. The preview needs a licensed Intune tenant, an authorized app with the Microsoft Graph application permission DeviceManagementScripts.ReadWrite.All, and local copies of both .ps1 files.

Use the row to check the package name and the proposed operation against the client’s change ticket. A newly created package has no assigned devices. Updating an existing package keeps its current assignments, so review those assignments before approving a replacement.

Before You Run It

  • Create an app registration with DeviceManagementScripts.ReadWrite.All (Graph beta) and grant admin consent. The tenant needs an Intune license.
  • Put the detection script and the remediation script on this computer and use their full paths.
  • Test the two scripts on a pilot PC before you assign the remediation to a group.
  • Choose RunAsAccount carefully: System by default, User only when the script needs the signed in user.
  • Run it with DryRun=true first to check the files and the tenant.
  • Assign it to a group and set its schedule yourself in the Intune admin center.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Creates (or with Update replaces) one Proactive Remediation in Intune; assigns it to nobody.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute.
  • Example answer: "Created the Intune remediation Clear Teams cache (ID 4c1f...); not assigned to any group yet"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The tenant ID (a GUID) or a domain such as contoso.onmicrosoft.com.
  • ClientId: The app registration's Application (client) ID, a GUID.
  • CertificateThumbprint: Thumbprint of the app's certificate (with its private key) in LocalMachine\My or CurrentUser\My on this computer. Leave empty only if you use the ClientSecret environment variable.
  • DisplayName: Name of the remediation in Intune. Required.
  • DetectionScriptPath: Full path of the detection script (.ps1) on this computer. Required.
  • RemediationScriptPath: Full path of the remediation script (.ps1) on this computer. Required.
  • Description: Description shown in Intune. Default empty.
  • Publisher: Publisher shown in Intune. Default MSP Outpost.
  • RunAsAccount: System (default) or User: whose context the scripts run in on the device.
  • RunAs32Bit: true runs the scripts in 32-bit PowerShell on 64-bit Windows. Default false.
  • EnforceSignatureCheck: true requires the scripts to be signed by a trusted publisher. Default false.
  • Update: true replaces an existing remediation with the same display name. Default false (refuse).

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

new-intune-remediation.ps1 · 1076 lines · 60.4 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.