Reinstalling DC Agent remotely via Intune (DC Cloud)

Reinstalling DC Agent remotely via Intune (DC Cloud)

Hi all,

We've been trialing DC for about two weeks now and decided to scale larger for a proof of concept. We deployed the agent via Intune, and it worked great for the most part. However, we had about ~75 machines that something happened during Agent installation and it was installed, but not communicating with the server. After working closely with support for a bit, it was determined the agent would need to be reinstalled manually on these devices. 

Great! I said, how can I do that remotely?

Well... you can't, at least according to ME Support as of yesterday. Which is a major bummer, but I never let a good challenge get in the way. So I've come up with a simple Powershell script for install/uninstall/reinstall of the Desktop Central agent that can be deployed via Intune (or modified for other platforms) that I'd like to share here, in hopes of two things:

1. That I hopefully save some poor future admin from having to go through all this again, and
2. That someone from the ME team sees this and forwards to support/engineering for verification, and maybe tweaked/posted as an official resource

Before I go any further, please note this script is provided AS IS, and neither ME (since it's their forum) nor I are responsible for any issues that may arise from using this in your environment.

Having gotten that out of the way, see below for the script:

  1. #Declares the switches as parameters
    [cmdletbinding()]
    param([switch]$Install,[switch]$Uninstall,[switch]$Reinstall)


    #This will run if script is called with -Install switch
    If ($Install)
    {
    cmd.exe /c 'setup.bat'
    }
    #This will run if script is called with -Uninstall switch
    elseif ($Uninstall)
    {
    $UninstallArgs=("/x",
    "{6AD2231F-FF48-4D59-AC26-405AFAE23DB7}",
    "MSIRESTARTMANAGERCONTROL=Disable",
    "REBOOT=ReallySupress",
    "/qn")

    Start-Process msiexec.exe -ArgumentList $UninstallArgs
    }
    #This will run if script is called with -Reinstall switch
    elseif($Reinstall)
    {
    $UninstallArgs=("/x",
    "{6AD2231F-FF48-4D59-AC26-405AFAE23DB7}",
    "MSIRESTARTMANAGERCONTROL=Disable",
    "REBOOT=ReallySupress",
    "/qn")
    $Removal= Start-Process msiexec.exe -ArgumentList $UninstallArgs -PassThru

    $Removal.WaitForExit()

    cmd.exe /c 'setup.bat'
    #This is optional, it generates a text file to use for Intune detection rules (can't use product code or registry since it will already exist prior to reinstall)
    New-Item C:\Windows\Temp\DCAReinstalled.txt
    }


In order to use this for Intune, save the above as Powershell script. Then copy the script and the following items all into one folder (these can be found by going to Agent > Agent Installation > Other Methods > Command Prompt > Download):

  1. DesktopCentralAgent.msi
  2. DesktopCentralAgent.mst
  3. DCAgentServerInfo.json
  4. Setup.bat
Now, use the IntuneWinAppUtil to wrap this all up into a .intunewin package, using DesktopCentralAgent.ps1 as the source file.

From here, go to Intune and create a new Win32 app, uploading the intunewin we just created. If you're doing this for the purpose of re-installing Desktop Central Agent, then for the Install command you'll use:
  1. Powershell -ExeuctionPolicy Bypass -File DesktopCentralAgent.ps1 -Reinstall
For the uninstall command, we can use:
  1. Powershell -ExecutionPolicy Bypass -File DesktopCentralAgent.ps1 -Uninstall


For detection methods, manually configure it to look for the file C:\Windows\Temp\DCAgentReinstalled.txt



Then assign away!

P.S., this script can be used to install/uninstall/reinstall the agent. To call a specific function, run
  1. DesktopCentralAgent.ps1 -Install
  2. DesktopCentralAgent.ps1 -Uninstall
  3. DesktopCentralAgent.ps1 -Reinstall