What is the difference between RestartRequired and RestartNeeded in Get-WindowsOptionalFeature output?

932 Views Asked by At

I run the following:

Get-WindowsOptionalFeature -Online -FeatureName TelnetClient | ConvertTo-Json -Depth 100

It produces the following output:

{
    "DisplayName":  "Telnet Client",
    "Description":  "Allows you to connect to other computers remotely.",
    "RestartRequired":  1,
    "CustomProperties":  [
                             {
                                 "Name":  "Description",
                                 "Value":  "Telnet Client uses the Telnet protocol to connect to a remote Telnet server and run applications on that server.",
                                 "Path":  "ServerComponent"
                             },
                             {
                                 "Name":  "DisplayName",
                                 "Value":  "Telnet Client",
                                 "Path":  "ServerComponent"
                             },
                             {
                                 "Name":  "Id",
                                 "Value":  "44",
                                 "Path":  "ServerComponent"
                             },
                             {
                                 "Name":  "Type",
                                 "Value":  "Feature",
                                 "Path":  "ServerComponent"
                             },
                             {
                                 "Name":  "UniqueName",
                                 "Value":  "Telnet-Client",
                                 "Path":  "ServerComponent"
                             },
                             {
                                 "Name":  "Major",
                                 "Value":  "10",
                                 "Path":  "ServerComponent\\Version"
                             },
                             {
                                 "Name":  "Minor",
                                 "Value":  "0",
                                 "Path":  "ServerComponent\\Version"
                             },
                             {
                                 "Name":  "Name",
                                 "Value":  "TelnetClient",
                                 "Path":  "ServerComponent\\Deploys\\Update"
                             }
                         ],
    "FeatureName":  "TelnetClient",
    "State":  0,
    "Path":  null,
    "Online":  true,
    "WinPath":  null,
    "SysDrivePath":  null,
    "RestartNeeded":  false,
    "LogPath":  "C:\\Windows\\Logs\\DISM\\dism.log",
    "ScratchDirectory":  null,
    "LogLevel":  2
}

My question is in particular about what is the difference between "RestartNeeded" and "RestartRequired"? They both appear to be about the same topic. What exactly is the difference between them?

"RestartRequired" is actually an enumeration (Microsoft.Dism.Commands.RestartType) with values:

Name Value
No 0
Possible 1
Required 2

(It is a pity that I am still using PowerShell 5.1 which lacks the -EnumsAsStrings option to ConvertTo-Json which was added in PowerShell 6 and 7.)

1

There are 1 best solutions below

0
On BEST ANSWER

Short Answer: On features like TelnetClient which return a [Microsoft.Dism.Commands.AdvancedFeatureObject]:

  • RestartRequired denotes whether a restart could be required after installing or enabling the feature
  • RestartNeeded is used to show whether a restart is currently pending for the feature.

Long Version: The AdvancedFeatureObject type never actually gets this value set though. Instead, the property is only used by Microsoft.Dism.Commands.ImageObject which is returned from Enable/Disable-WindowsOptionalFeature. For example:

# I already have it installed:
Get-WindowsOptionalFeature -Online -FeatureName 'TelnetClient' | fl FeatureName,State,Restart*

FeatureName      : TelnetClient
State            : Enabled
RestartNeeded    : False
RestartRequired  : Possible

# I remove it, and save the output:
$result = Get-WindowsOptionalFeature -Online -FeatureName 'TelnetClient'| 
    Disable-WindowsOptionalFeature

# Returns an ImageObject
($result|gm).TypeName
Microsoft.Dism.Commands.ImageObject

# RestartNeeded is set here
$result

Path          :
Online        : True
RestartNeeded : True

# It does not get set on the main object though (only State=Disabled):

FeatureName     : TelnetClient
State           : Disabled
RestartRequired : Possible
RestartNeeded   : False

I think the RestartNeeded property is only present on the AdvancedFeatureObject due to some type inheritance, and is not actually a useful property.