Skip to content
Menu

Lost or Returned Laptop - Remote Wipe or Retire in Intune

Queues Wipe (factory reset by default) or Retire (remove company data and apps) for one Intune device by name or ID. Dry run until you approve it.

Lost or returned laptop - remote wipe or retire in Intune 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 Lost or returned laptop - remote wipe or retire in Intune. 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: DeviceManagementManagedDevices.PrivilegedOperations.All and .Read.All; Intune
Changes thingsChanges what it runs on

What It Does

Risk is High, so the script only finds the device and says what it would send unless you set DryRun=false and Approve=invoke-device-wipe. It signs in to one client tenant as your app registration, lists the Intune devices and picks the one whose name matches DeviceName exactly, or the one with DeviceId. A name that matches more than one device is refused, with the IDs listed so you can choose.

Mode Wipe (the default) resets the device to factory state and erases all data on it. KeepEnrollmentData and KeepUserData keep the enrollment or the user's data on a Windows device. Mode Retire removes company data and apps and takes the device out of Intune, leaving the owner's own data; it is the right action for a personal phone or laptop. A device Intune lists as personally owned is refused for Wipe unless AllowPersonalWipe is true.

Intune only queues the action: the device acts the next time it checks in, so a laptop that is off acts when it next connects. The answer says the request was accepted, not that the device has wiped. Before sending, the script reads the device's pending actions, and while a wipe or retire is still queued it ends OK with Already requested instead of sending a second one.

It deletes nothing from Intune or Entra ID and does not disable the user. Pair it with invoke-m365-offboarding or invoke-compromised-account-containment when a person leaves or an account is compromised.

Before You Run It

  • Create an app registration in the client tenant with the Graph application permissions DeviceManagementManagedDevices.PrivilegedOperations.All and DeviceManagementManagedDevices.Read.All, and give admin consent.
  • Check the device name or ID in the Intune admin center and do a dry run first.
  • A wipe cannot be undone. Make sure nothing on the device is still needed, and use Retire for personal devices.

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: High. It is a dry run unless you set both DryRun=false and Approve=invoke-device-wipe, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
  • What it changes: Queues an Intune Wipe (factory reset, all data erased) or Retire (company data removed) for one device.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute.
  • Example answer: "Wipe requested for LAPTOP-0042 (Windows, a.chen@contoso.com); the device acts when it next checks in"
  • 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.
  • DeviceName: The device's name in Intune (exact match, any case). Give DeviceName or DeviceId.
  • DeviceId: The device's Intune managed device ID (a GUID). Give DeviceName or DeviceId.
  • Mode: Wipe (default) or Retire.
  • KeepEnrollmentData: Wipe only. true keeps the enrollment state and the user account on a Windows device. Default false.
  • KeepUserData: Wipe only. true keeps the user data on a Windows device. Default false.
  • AllowPersonalWipe: true allows a full Wipe of a device Intune lists as personally owned. Default false (use Retire for those).

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

invoke-device-wipe.ps1 · 1059 lines · 59.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.