Enabling Windows Features and their dependencies...

Duchemin, Dominique 2,006 Reputation points
2022-05-13T06:03:24.393+00:00

Hello,

I am using this command:
Enable-WindowsOptionalFeature -Online -FeatureName “Windows-Defender-Features” -all

But the results is only for the main item "Windows Defender Features" which is enabled not the dependency "Windows Defender" ...

201577-2022-05-12-22-58-33-windows-defender.png

Thanks,
Dom

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 31,571 Reputation points
    2022-05-15T14:18:34.267+00:00

    Reference:

    https://learn.microsoft.com/en-us/powershell/module/dism/enable-windowsoptionalfeature?view=windowsserver2016-ps

    -NoRestart
    Suppresses reboot. If a reboot is not required, this command does nothing. This option will keep the application from prompting for a restart or keep it from restarting automatically.
    -All
    Enables all parent features of the specified feature. If a parent feature is required for the specified feature to be enabled in the image, All will enable the parent and all of its default dependencies.

    To supress the reboot prompt add the -norestart switch.

    As to why the GUI gets installed... I do not have a VM with the same OS as your server, so I can't test for you.

    Based on your replies you apparently have a parent feature; Windows-Defender-Features, and a sub feature; Windows-Defender.

    If you installed Windows-Defender, and it didn't work, then that would indicate to me that it's parent feature might also be required. But since you don't want the GUI, then you don't want to use the -All switch because the GUI might be tagged as a default.

    If you are testing on the same machine, make sure that all defender features are uninstalled and you reboot before trying again.

    Try this:

    Enable-WindowsOptionalFeature -Online -FeatureName "Windows-Defender-Features" -NoRestart  
    Enable-WindowsOptionalFeature -Online -FeatureName "Windows-Defender" -NoRestart  
    add shutdown to reboot if desired/required  
    

    Update: What is the issue with installing the GUI feature? If I have a server that I suspect is compromised, then I would RDP to it, verify that the definitions are up to date, and then initiate a full system scan, most likely using the GUI interface. I don't know what specific functionality that feature enables, but it seems to me that at worst, it shouldn't hurt anything, and at best, I would need it to manage Defender.

    1 person found this answer helpful.
    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. MotoX80 31,571 Reputation points
    2022-05-13T13:39:37.373+00:00

    The -All switch is for parent features and dependencies.

    https://learn.microsoft.com/en-us/powershell/module/dism/enable-windowsoptionalfeature?view=windowsserver2022-ps

    The easiest solution appears to be using Get-WindowsOptionalFeature and filtering on FeatureName to identify every feature that you wish to install and then piping that to Enable-WindowsOptionalFeature.

    To test, I used this command to list the printing features. This is on Win10.

    Get-WindowsOptionalFeature -Online -FeatureName "printing-foundation*" | Sort-Object | Format-Table  
    

    Then installed with this command.

    Get-WindowsOptionalFeature -Online -FeatureName "printing-foundation*" | Enable-WindowsOptionalFeature -Online  
    
    1 person found this answer helpful.
    0 comments No comments

  2. MotoX80 31,571 Reputation points
    2022-05-13T17:22:02.883+00:00

    don't want the GUI enabled

    You can exclude that with a where-object.

    Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Where-Object -Property FeatureName -NotLike '*GUI*' | Format-Table
    

    To install:

    Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Where-Object -Property FeatureName -NotLike '*GUI*' |  Enable-WindowsOptionalFeature -Online
    
    1 person found this answer helpful.
    0 comments No comments

  3. Duchemin, Dominique 2,006 Reputation points
    2022-05-13T16:44:58.617+00:00

    Hello,

    I tried
    Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender-Features*,Windows-Defender*" | Sort-Object | Format-Table

    This does not show anything!!!

    This is the one which works....

    PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Sort-Object | Format-Table

    FeatureName State DisplayName Description RestartRequired CustomProperties


    Windows-Defender Disabled Windows Defender Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, InstallWi...
    Windows-Defender-Features Enabled Windows Defender Features Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, Type...}
    Windows-Defender-Gui Disabled GUI for Windows Defender GUI for Windows Defender. Possible {Description, DisplayName, Id, Parent...}

    This one is showing 3 items but I just need 2 so continuing with the enabling.... but I don't want the GUI enabled !!!

    Thanks,
    Dom

    0 comments No comments

  4. Duchemin, Dominique 2,006 Reputation points
    2022-05-14T21:28:53.413+00:00

    Hello,

    On the first test it failed...


    PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Where-Object -Property FeatureName -NotLike 'GUI' | Format-Table
    Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Where-Object -Property FeatureName -NotLike 'GUI' | Enable-WindowsOptionalFeature -Online
    Get-WindowsOptionalFeature -Online -FeatureName "Windows-Defender*" | Where-Object -Property FeatureName -NotLike 'GUI' | Format-Table

    FeatureName State DisplayName Description RestartRequired CustomProperties


    Windows-Defender-Features Enabled Windows Defender Features Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, Type...}
    Windows-Defender Disabled Windows Defender Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, InstallWi...

    Path :
    Online : True
    RestartNeeded : False

    Enable-WindowsOptionalFeature : The referenced assembly could not be found.
    At line:2 char:126

    • ... FeatureName -NotLike 'GUI' | Enable-WindowsOptionalFeature -Online
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
    • FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

    FeatureName State DisplayName Description RestartRequired CustomProperties


    Windows-Defender-Features Enabled Windows Defender Features Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, Type...}
    Windows-Defender Disabled Windows Defender Windows Defender helps protect your machine from malware. Possible {Description, DisplayName, Id, InstallWi...


    But on the second it works ... but not as expected

    it needs a reboot so how to do it automatically?

    201995-2022-05-14-14-21-10-vipsccmdp02-install-windows-de.png

    and also the exclusion of the GUI does not work...

    202011-2022-05-14-14-26-27-vipsccmdp02-install-windows-de.png

    Checking again...

    Thanks,
    Dom

    0 comments No comments