Microsoft365 Consultant and Microsoft Certified Trainer

Problem definition

Recently at a customer I was asked if it was possible, in preparation for their new modern workplace, that the end user could reset his device himself. Basically, the same as the famous "wipe" button in Intune.
I had indicated that this can be done by means of the following ways:

  1. End user goes to the Settings app ➡️ Update & Security ➡️ Recovery ➡️ Get Started and follow the wizard
  2. End user chooses CTRL + Windowskey + R on the sign-in screen
  3. In the Run field, type systemreset.exe and follow the wizard
  4. Oh.. and the last option is to open the Company Portal ➡️ Devices ➡️ This Device ➡️ Actions ➡️ Reset

A requirement of the customer was that the end users may not be a local admin, so option 2 is dropped. They also wanted to protect the end user from the unnecessary questions that arise when choosing options 1 and 3. So they also fall off. Option 4 is to many clicks for the end-user. So there is nothing left. But we still want to offer a service with which the user can reset his device.

🤔

So, how does Intune work?
I don't know if I can judge this as a command, but after some research I ended up on this forum post: https://techcommunity.microsoft.com/t5/windows-deployment/factory-reset-windows-10-without-user-intervention/m-p/1349038/highlight/true#M559. There is a piece of script there that Intune also uses in theory. So if we can cram that piece nicely into a Win32 app with a nice warning?

💡💡💡💡💡

The win32app
The win32app is really nothing more than a powershell script. For the sake of simplicity, I will divide it in two.

Part 1: Warning window
As soon as the end user presses install, the script starts immediately without any kind of warning. So perhaps so neat to at least provide the end user with a warning and some tips before continuing.

For this I use the System.Windows.Forms language to create a popup containing the text, two buttons, and their formatting. I will not go into more detail here, except that you can add a title bar icon yourself by means of a base64 code. Websites enough that can do this for you.

# Show a messagebox where the enduser can accept or decline the reset
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# Create the form.
$form  = New-Object system.Windows.Forms.Form
$form.Width   = "400"
$form.Height  = "375"
$form.Text = "Reset My Device"
$form.AutoSize = $true
$form.Topmost = $true
$form.StartPosition = "CenterScreen"
$form.BackColor = "Orange"
$form.ForeColor = "Black"
# This base64 string holds the bytes that make up the Waternet icon for a 32x32 pixel image
$iconBase64      = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAA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jl4Q7NmCyITV8Nc8DTv/Xui2tznXklkP6O5Q5wd/0f9KE5vRS8+X2txofSac6/+E+FM0HA0hXZxsIKUBSqADkodp1RGRofPgS2f1zckINq/QfoGQHS0hJ/JFD5G1xDadYfUaAavTAL1H/MXx8D9YCDRrq+lR7yk7Qs++Efblv0L8uVuUd1RvyD6jIU/AWzmLafnDsPGSYVRpgBIoU9Nl7f73w+p8tX7m796EYMcGTZ/iFUZL1hHN2+tGJm/dfHjvzdXjyNAXEJvcUff9lc4qslqj349YgMTyR5QTpN+ou09ovGD7eyTNojLXZAJpGUCgBBUr5CyzaJKFkRYsm5nHZdakjhBik0UREoHu3NAXB2lfci/PPTWsKWSApVCyehudsEb/J0nihVHqKRoWWepFpG2AEoRxTndXWSuXMgTkQbU9ZvKhj3CDnkveiP7kY8TnjyWxvlshtsPN1vtCEty7RXefQ3abZ0kg1djE8mDSGZaBSDNU/zJWJb7LP7Qec9ZjM/sxtmeRACtqC11EadIcrmxzcZqEvXtZYit3XqaQcR/TWsI9SPKcAnvgVA2L8tDmarPj4c6+VM91yAviOdkwQuaDjJA1e2/F4zBP6qNL16mqQvUsGiH+1xsQ7NsG52bK8WrW9usCWTEAR6etdnfONXAGPaoxnxJihNy2LJYom0mqzuDHw6Ipg8iOAQh1cwoh/5N/wTyxR+WKT4yQ0xqJf/wK/p7PKMTuVmGUKWTNAALtN749E0aHi8JMUhnUCHnUBpTMVJGyFzlTErnGafCbQvSEGEJFjvyyhEcVkApSNmTqXsUM6IKseoBABqGDSWPwAkm1mRo8APwfy2q+pCIaH20AAAAASUVORK5CYII='
$iconBytes       = [Convert]::FromBase64String($iconBase64)
# initialize a Memory stream holding the bytes
$stream          = [System.IO.MemoryStream]::new($iconBytes, 0, $iconBytes.Length)
$Form.Icon       = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::new($stream).GetHIcon()))

$TextBox = New-Object System.Windows.Forms.label
$TextBox.Location = New-Object System.Drawing.Size(10,10)
$TextBox.Size = New-Object System.Drawing.Size(400,250)
$TextBox.Margin = New-Object System.Windows.Forms.Padding(10, 10, 10, 10)
$TextBox.BackColor = "Transparent"
$TextBox.Font = "Segoe UI, 10"
$TextBox.Text = "CAUTION!
Starting this app will reinstall your device.

ATTENTION!
The hard drive on your device will be totally erased during this action. So only proceed if your important files are stored on OneDrive or SharePoint and the synchronization is complete!

IMPORTANT!
During this entire action, the laptop must be powered. So make sure your device is directly connected to a charger or docking station before proceeding!

Click CONTINUE to start the reset or CANCEL to stop it."

$form.Controls.Add($TextBox)

The magic
The end user has received a warning window with two buttons. A CONTINUE and a CANCEL button. But what happens when the end user presses the CONTINUE button?
Well...

Do you have a moment?
⏱️⏱️
Time is up.

As soon as you press the CONTINUE button, the following script will take effect. This script is based on the local MDM WMI Bridge Provider.

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,300)
$okButton.Size = New-Object System.Drawing.Size(100,23)
$okButton.Text = 'CONTINUE'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::Yes
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(250,300)
$cancelButton.Size = New-Object System.Drawing.Size(100,23)
$cancelButton.Text = 'CANCEL'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::No
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$Result = $form.ShowDialog()

switch  ($Result) {

    'Yes' {

        # Dispose the form and its controls. Skip, if you want to redisplay the form later.
        $form.Close()
        $stream.Dispose()
        $form.Dispose()

        # And this is where the magic happens
        $namespaceName = "root\cimv2\mdm\dmmap"
        $className = "MDM_RemoteWipe"
        $methodName = "doWipeProtectedMethod" #change this to doWipeMethod if you run this app on Surface devices

        $session = New-CimSession

        $params = New-Object Microsoft.Management.Infrastructure.CimMethodParametersCollection
        $param = [Microsoft.Management.Infrastructure.CimMethodParameter]::Create("param", "", "String", "In")
        $params.Add($param)

        $instance = Get-CimInstance -Namespace $namespaceName -ClassName $className -Filter "ParentID='./Vendor/MSFT' and InstanceID='RemoteWipe'"
        $session.InvokeMethod($namespaceName, $instance, $methodName, $params)

    }

If you press the CANCEL button, the warning window is closed, and nothing happens to that particular device.

    'No' {
        
        # Dispose the form and its controls. Skip, if you want to redisplay the form later.
        $form.Close()
        $stream.Dispose()
        $form.Dispose()
        exit
    }
}

Create and deploy
I do think we all know how to make a win32app these days, so I'll skip that, but I'll tell you what you need to do in Intune to deploy the app.

  1. Go to the Enpoint Manager portal
  2. Go to Apps ➡️ Windows and click on + Add
  3. In the dropdown list, select Windows app (Win32)
  4. Click on Select
  5. Click on Select app package file
  6. Browse to the intunewin file, that you created or downloaded from my GitHub
  7. Click on OK
  8. Fill in a Name, Description and the Publisher. If you want you can fill in the rest of the fields as well
Figure 01 - App information
  1. Click on Next
  2. At the Install command field, type this:
    .\serviceui.exe -process:explorer.exe "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -NoProfile -File ".\Reset-MDMWipeDevice.ps1"
  3. At the Uninstall command field, type this:
    cmd.exe /c del %ProgramData%\TheOrangeCat\ResetMDMDevice\Reset-MDMWipeDevice.ps1.tag
  4. Leave the rest as default
Figure 02 - Program options
  1. Click on Next
  2. Choose at the Operating System architecture for 64-bit
  3. Choose at the Minimum operating system a value that suits your environment
  1. Click on Next
  2. From the Rules format dropdown, select Manually configure detection rules
  3. Click on + Add
  4. At the Rule type dropdown, select File
  5. In the Path field, type %ProgramData%\TheOrangeCat\ResetMDMDevice\
  6. In the File or folder field, type Reset-MDMWipeDevice.ps1.tag
  7. From the Detection method dropdown, select File or folder exist
  8. Click on OK
Figure 03 - Detection rules
  1. Click on Next
  2. Click on Next
  3. Click on Next
  4. On the Assignments tab, choose an Azure AD group with your users and select them as avaialble.
  5. Click on Next
  6. Review your settings and click on Create

App in action
In the video below you can clearly see what the end user will see as soon as he / she installs the app.

Complete script
That is below, but it can be found on my [GitHub repository] (https://github.com/BurgerhoutJ/scripts/tree/main/reset-my-device) as well including the intunewin file and a fancy app icon.

# Reset and wipe an Intune managed Windows 10/11 device
# Created by Jeroen Burgerhout (@BurgerhoutJ)

# Create a tag file just so Intune knows this was installed (Just for the fun)
if (-not (Test-Path "$($env:ProgramData)\TheOrangeCat\ResetMDMDevice"))
{
    Mkdir "$($env:ProgramData)\TheOrangeCat\ResetMDMDevice"
}
Set-Content -Path "$($env:ProgramData)TheOrangeCat\ResetMDMDevice\Reset-MDMWipeDevice.ps1.tag" -Value "Installed"

# Show a messagebox where the enduser can accept or decline the reset
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# Create the form.
$form  = New-Object system.Windows.Forms.Form
$form.Width   = "400"
$form.Height  = "375"
$form.Text = "Reset My Device"
$form.AutoSize = $true
$form.Topmost = $true
$form.StartPosition = "CenterScreen"
$form.BackColor = "Orange"
$form.ForeColor = "Black"
# This base64 string holds the bytes that make up the Waternet icon for a 32x32 pixel image
$iconBase64      = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAIWaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8P3hwYWNrZXQgYmVnaW49J++7vycgaWQ9J1c1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCc/Pgo8eDp4bXBtZXRhIHhtbG5zOng9J2Fkb2JlOm5zOm1ldGEvJyB4OnhtcHRrPSdJbWFnZTo6RXhpZlRvb2wgMTAuODAnPgo8cmRmOlJERiB4bWxuczpyZGY9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMnPgoKIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PScnCiAgeG1sbnM6cGRmPSdodHRwOi8vbnMuYWRvYmUuY29tL3BkZi8xLjMvJz4KICA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7RXefQ3abZ0kg1djE8mDSGZaBSDNU/zJWJb7LP7Qec9ZjM/sxtmeRACtqC11EadIcrmxzcZqEvXtZYit3XqaQcR/TWsI9SPKcAnvgVA2L8tDmarPj4c6+VM91yAviOdkwQuaDjJA1e2/F4zBP6qNL16mqQvUsGiH+1xsQ7NsG52bK8WrW9usCWTEAR6etdnfONXAGPaoxnxJihNy2LJYom0mqzuDHw6Ipg8iOAQh1cwoh/5N/wTyxR+WKT4yQ0xqJf/wK/p7PKMTuVmGUKWTNAALtN749E0aHi8JMUhnUCHnUBpTMVJGyFzlTErnGafCbQvSEGEJFjvyyhEcVkApSNmTqXsUM6IKseoBABqGDSWPwAkm1mRo8APwfy2q+pCIaH20AAAAASUVORK5CYII='
$iconBytes       = [Convert]::FromBase64String($iconBase64)
# initialize a Memory stream holding the bytes
$stream          = [System.IO.MemoryStream]::new($iconBytes, 0, $iconBytes.Length)
$Form.Icon       = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::new($stream).GetHIcon()))

$TextBox = New-Object System.Windows.Forms.label
$TextBox.Location = New-Object System.Drawing.Size(10,10)
$TextBox.Size = New-Object System.Drawing.Size(400,250)
$TextBox.Margin = New-Object System.Windows.Forms.Padding(10, 10, 10, 10)
$TextBox.BackColor = "Transparent"
$TextBox.Font = "Segoe UI, 10"
$TextBox.Text = "CAUTION!
Starting this app will reinstall your device.

ATTENTION!
The hard drive on your device will be totally erased during this action. So only proceed if your important files are stored on OneDrive or SharePoint and the synchronization is complete!

IMPORTANT!
During this entire action, the laptop must be powered. So make sure your device is directly connected to a charger or docking station before proceeding!

Click CONTINUE to start the reset or CANCEL to stop it."

$form.Controls.Add($TextBox)

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,300)
$okButton.Size = New-Object System.Drawing.Size(100,23)
$okButton.Text = 'CONTINUE'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::Yes
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(250,300)
$cancelButton.Size = New-Object System.Drawing.Size(100,23)
$cancelButton.Text = 'CANCEL'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::No
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$Result = $form.ShowDialog()

switch  ($Result) {

    'Yes' {

        # Dispose the form and its controls. Skip, if you want to redisplay the form later.
        $form.Close()
        $stream.Dispose()
        $form.Dispose()

        # And this is where the magic happens
        $namespaceName = "root\cimv2\mdm\dmmap"
        $className = "MDM_RemoteWipe"
        $methodName = "doWipeProtectedMethod" #change this to doWipeMethod if you run this app on Surface devices

        $session = New-CimSession

        $params = New-Object Microsoft.Management.Infrastructure.CimMethodParametersCollection
        $param = [Microsoft.Management.Infrastructure.CimMethodParameter]::Create("param", "", "String", "In")
        $params.Add($param)

        $instance = Get-CimInstance -Namespace $namespaceName -ClassName $className -Filter "ParentID='./Vendor/MSFT' and InstanceID='RemoteWipe'"
        $session.InvokeMethod($namespaceName, $instance, $methodName, $params)

    }
    'No' {
        
        # Dispose the form and its controls. Skip, if you want to redisplay the form later.
        $form.Close()
        $stream.Dispose()
        $form.Dispose()
        exit
    }
}

Thanks for reading this post. See you next time!