The Uninstall-WindowsFeature cmdlet allows you to remove specific Windows features. However, this cmdlet only works in a 64-bit PowerShell instance, and since Automox scripts run in a 32-bit PowerShell environment, you need to use a script block to execute this cmdlet successfully.
This guide explains how to use a script block in Automox to run Uninstall-WindowsFeature.
Steps
- Open the Automox console and navigate to the Worklets section.
- Create a new Worklet or modify an existing one.
- Use the following script to wrap your code in a script block:
$scriptBlock = {
Uninstall-WindowsFeature -Name "FeatureName"
}
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock
- Replace "FeatureName" with the actual feature you want to uninstall.
- Save and deploy the Worklet to your desired devices.
Example
Here is an example to uninstall the "Telnet-Client" feature:
$scriptBlock = {
Uninstall-WindowsFeature -Name "Telnet-Client"
}
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock
Troubleshooting
- Exit Code Issues: Check the $exitCode variable for details about the error. A non-zero exit code indicates an issue during execution.
- Agent Errors: Verify the Automox agent is running and has the required permissions.