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:
- 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
- Convert the Script to an Intune Package:
Use
IntuneWinAppUtil.exe
to convert this script into a format suitable for Intune. - 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.
- 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.