Remove-WindowsFeature (PS)

Remove a Windows feature from a running installation and use the return code for further action.

Import-Module ServerManager
$status = Remove-WindowsFeature Server-Media-Foundation

  if ($status.Success -eq $true) 
    {if ($status.RestartNeeded -eq "Yes") 
      {$exitCode=3010}} else {$exitCode=-1}

[Environment]::Exit($exitCode)