Using Uninstall-WindowsFeature in a Worklet

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

  1. Open the Automox console and navigate to the Worklets section.
  2. Create a new Worklet or modify an existing one.
  3. 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
  1. Replace "FeatureName" with the actual feature you want to uninstall.
  2. 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.
Was this article helpful?
0 out of 0 found this helpful