Uninstall the Microsoft Intune client via PowerShell

This post will be a short and quick follow-up on my post earlier this week about uninstalling the Microsoft Intune client. The second method I mentioned in that post was about using the ProvisioningUtil.exe. Personally I think the actions mentioned in that method are too many manual actions, so I created a small PowerShell script with two functions to do exactly the same. In this post I’ll go through the two functions, and how they come together, in three steps.

>> The complete script is available via download here on the TechNet Galleries! <<

Step 1: Get the ServiceId

The first step is that I need to get the service ID for the uninstall command line. The following function goes through the registry path that contains the registry key with the service ID. It simply gets all the items in the specified registry path and loops through it until it finds a GUID. There are no special checks required as that registry path will only contain one registry key with a GUID.

function Get-ServiceId { $RegistryPath = ` "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\OnlineManagement" try { $RegistryItems = (Get-ChildItem ` -Path Registry::$RegistryPath -ErrorAction Stop).Name foreach ($RegistryItem in $RegistryItems) { if ($RegistryItem.StartsWith("$RegistryPath\{")) { $ServiceId ` = $RegistryItem.Replace("$RegistryPath\","") break } } return $ServiceId } catch { Write-Output "The Microsoft Intune client is not installed" } }

Step 2: Trigger the uninstall

The next step is that I have to use the service ID in the uninstall command line. The following function uses the service ID to trigger the uninstall of the Microsoft Intune client. That’s also why the service ID is a required parameter for this function. It’s good to note that this function uses the default installation path of the Microsoft Intune client. In case this is adjusted, the value of the variable $ProvisioningUtilPath has to be adjusted.

function Start-Uninstall { param ( [parameter(Mandatory=$true)]$ServiceId ) try { $ProvisioningUtilPath = ` "C:\Program Files\Microsoft\OnlineManagement\Common" $ProvisioningUtilExecutable = ` "ProvisioningUtil.exe" $ProvisioningUtilArguments = ` "/UninstallClient /ServiceId $ServiceId ` /TaskName 'tempTask' /SubEventId 16" Start-Process -FilePath "$($ProvisioningUtilPath)\` $($ProvisioningUtilExecutable)" ` -ArgumentList $ProvisioningUtilArguments -Wait -PassThru } catch { Write-Output "Failed to trigger the uninstall of the ` Microsoft Intune client" } }

Step 3: Usage

The third and last step is to bring the two functions together. This can be achieved by calling the second function with the result of the first function as the input. This also means that the complete script, which is available via the TechNet Gallaries, doesn’t require any specific input parameters.

Start-Uninstall (Get-ServiceId)

9 thoughts on “Uninstall the Microsoft Intune client via PowerShell”

    • Thanks Stéphane!

      I think it should be quite simple to deploy the Microsoft Intune client via PowerShell. I just ran the executable with /? and it has the following silent possibilities:
      /Quiet Used to run enrollment package installation in quiet mode.
      /Extract Used to extract enrollment packages (Microsoft_Intune_{X86,X64}.msi) destination. Specifies the directory for the extracted package.
      /PrepareEnroll Used to prepare the reference machine for automatic enrollment after Windows Setup.


  1. Script works well without any issue.. but it ask to execute policy which is by default on a Win10 machine machine is set as Restricted…

    Do we have a way to run this script without setting execution policy Unrestricted

  2. The link to get the complete script takes me to a samples page, but not to the complete script (browsed all the entries and did search for ‘remove intune’ and just ‘intune’, and it returned no results). Is there any way you could post the complete script here, or let me know how to get the complete script? I tried piecing the sections together without any luck- I used to use the script all the time (complete script used to be posted), but can’t get the 3 sections to work correctly piecing them together into a single script….


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.