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)

Share

Uninstall the Microsoft Intune client

This blog post will be relatively short, but will address a common “issue” with the Microsoft Intune client and that’s the uninstall of the client. I know it’s been addressed already in a couple of blogs, but that seems to be all outdated information. Sometimes even an old batch file with all “hard-coded” MSI GUIDs is mentioned, well that’s definitely outdated by now. In my opinion there are only two real methods to uninstall the Microsoft Intune client. The first one is via the Microsoft Intune administration console and the second one is via the ProvisioningUtil.exe on the client machine. In this blog post I’ll go through both methods.

Method 1 – Microsoft Intune administration console

The first method is, by far, the easiest. This method will simply use the method that was designed to uninstall the client, and that’s using the Microsoft Intune administration console. It will simply create a scheduled task to uninstall the Microsoft Intune client and all the related components by using ProvisioningUtil.exe. This whole process can be followed in the Enrollment.log that is located in C:\Program Files\Microsoft\OnlineManagement\Logs. As anyone can imagine, this is many times better than a batch file with hard-coded MSI GUIDs, because those MSI GUIDs happen to change a lot. To trigger the uninstall of the Microsoft Intune client simply follow the next steps:

  • Retire_WipeLogon on to the Microsoft Intune administration console;
  • Navigate to Groups > All Computers and select the Devices tab;
    • Note: This can be any other Group that contains the device;
  • Retire_Wipe_DeviceSelect the device, click  Retire/Wipe and the Retire device: <device> dialog box will show;
  • Notice that Wipe the device before retiring is grayed out and click Yes;
  • Within a couple of minutes the uninstall process will be triggered on the client.

Method 2 – ProvisioningUtil.exe

The second method is a bit more difficult. This method requires one to manually run ProvisioningUtil.exe. The good readers might notice that this is the same executable, that’s being triggered, as via the retire/wipe action of the Microsoft Intune administration console. It also works the same and also creates the same scheduled task. In previous releases the uninstall command was as simple as ProvisioningUtil.exe /UninstallAgents /WindowsIntune, but this has changed with the latest releases. To be completely sure about this statement, simply navigate to C:\Program Files\Microsoft\OnlineManagement\Common and run ProvisioningUtil.exe /?. This will provide an overview about the following possible parameters:

  • image/UninstallClient – Used to uninstall the Microsoft Intune or AIS client from the machine;
  • /ServiceId – Used to specify a specific service id to scan against;
  • /TaskName – Used to specify the task to be deleted after a successful scan/download/install;
  • /SubEventId – Used to specify the sub event Id that needs to be reported for telemetry.

The funny thing, or maybe annoying for some, is that, even though the help information about ProvisioningUtil.exe indicates that not all parameters are required, all parameters are required. What makes it even better is that it doesn’t seem to use them all, but I wouldn’t be surprised to see that change in the near future. This means that it’s simply copying the example of ProvisioningUtil.exe /UninstallClient /ServiceId {GUID} /TaskName “tempTask” /SubEventId 16 and it’s almost good to go. The only piece of missing information is the GUID of the service. Locally on the client this information can be retrieved from at least one of the following places:

1 EnrollmentLogAfter the installation of the Microsoft Intune client the service ID can be found in the Enrollment.log, by searching on the sentence Initializing for service ID. This will show the GUID of the service.
2 RegistryAfter the installation of the Microsoft Intune client the service ID can be found in the OnlineManagement key that is located at HKLM\SOFTWARE\Microsoft\. This will show a key with the GUID of the service.

This completes the required information and in my case this creates a command line like this: Uninstall_CommandProvisioningUtil.exe /UninstallClient /ServiceId “{3DA21691-E39D-4DA6-8A4B-B43877BCB1B7}” /TaskName “tempTask” /SubEventId 16. To follow the uninstallation of the Microsoft Intune client take a look again at the Enrollment.log. This will also show that it slightly changed the last two parameters of the provided command line.

Note: A manual uninstall of the Microsoft Intune client doesn’t remove the device from the Microsoft Intune administration console.

Share