How do I run uninstall script in Intune app

James Gledson 190 Reputation points
2023-12-22T14:43:43.6133333+00:00

I used the IntuneWinApp utility to make an app that runs this simple PowerShell: Add-WindowsCapability -Online -Name "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0"

Is there a way to incorporate the uninstall command with in the same app? Remove-WindowsCapability -Name Rsat.ServerManager.Tools~~~~0.0.1.0 -Online

Thanks

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Configuration
0 comments No comments
{count} votes

Accepted answer
  1. Carlos Solís Salazar 18,191 Reputation points MVP Volunteer Moderator
    2023-12-22T23:13:39.9566667+00:00

    In Microsoft Intune, you can specify both install and uninstall commands for an app, but they need to be defined separately within the app's configuration. For PowerShell scripts like the ones you're using to install and uninstall Windows capabilities, you'll have to create two different packages: one for installation and another for uninstallation. Here's how you can set this up:

    1. Creating the Installation Package:

    You've already created an installation package using the IntuneWinAppUtil.exe utility with your PowerShell script:

    Add-WindowsCapability -Online -Name "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0"
    

    2. Creating the Uninstallation Package:

    To create an uninstallation package, you'll need to follow similar steps but with the uninstall command:

    1. Create a PowerShell Script for Uninstallation: Write a PowerShell script with the uninstall command. Save this as UninstallScript.ps1 or a similar name.
         Remove-WindowsCapability -Name "Rsat.ServerManager.Tools~~~~0.0.1.0" -Online
      
    2. Convert the Script to an Intune Package: Use IntuneWinAppUtil.exe to convert this script into a format suitable for Intune.
    3. Upload the Uninstallation Package to Intune:
      • In the Microsoft Endpoint Manager admin center, go to Apps > All apps > Add.
      • Choose the app type as “Windows app (Win32)” and upload the uninstallation package created by IntuneWinAppUtil.exe.
      • Configure the app information.
    4. Specify the Uninstall Command: In the program settings of the app, specify the uninstall command. This would typically involve running the PowerShell script in a similar manner to your install script. Example:
         PowerShell.exe -ExecutionPolicy Bypass -File "UninstallScript.ps1"
      

    3. Assign the Packages:

    • Assign the installation package to the necessary user or device groups for deployment.
    • The uninstallation package can be assigned similarly, or it can be used to remove the capability when necessary.

    4. Testing:

    • Before wide deployment, test both installation and uninstallation scripts on a test device to ensure they work as expected.

    5. Deployment:

    • Once tested, deploy the installation and uninstallation scripts as required in your environment.

    By following these steps, you'll be able to manage both the installation and uninstallation of the Windows capability via Intune. Remember that the uninstall script/package should be separately deployed and is not automatically executed when the install package is removed from Intune assignments.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ZhoumingDuan-MSFT 17,165 Reputation points Microsoft External Staff
    2023-12-25T01:35:17.75+00:00

    @James Gledson,Thanks for posting in Q&A.

    From your description, I know that you want to incorporate the install and uninstall command within the same app.

    Based on my research, you can refer the method @Carlos Solís Salazar mentioned.

    However, there is one alternative way to achieve. You can find the msi file of the app, use the IntuneWinApp utility to convert it to intunewin file, upload the intunewin file into the Intune, it will automatically cover the install command and uninstall command, and then you can deploy it to device.

    Hope above can be helpful. If there is any update, feel free to contact me.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.