If your client systems are connected to the Internet: Use Group Policy
Set the Group Policy to go directly to Windows Update for optional features. This is the easiest way but relies on communication with Windows Update to download and install the optional components.
Computer Configuration > Policies > Administrative Templates >System > Specify settings for optional component installation and component repair
Set it to Enabled
Alternate source file path: <BLANK>
Never attempt to download payload from Windows Update: Disabled
Download repair content and optional features directly from Windows Update instead of Windows Server Update Services (WSUS): Enabled
If your client systems are not connected to the Internet: Use Group Policy
Set the Group Policy to go to a local repository for optional features. This is the easiest way but relies on keeping the local repository current with your systems versions.
First let us create the local repository. You will need the cab files for the Optional Components – either from the Windows 10 Installation media (media\sources\sxs) (limited optional components) or from the Microsoft Business Center download site (Windows 10 Features on Demand / Windows Server Features on Demand) and create a shared UNC folder for your local repository of the .cab files. If you downloaded the Features on Demand ISOs from the Business Center, you will need to extract the iso files to reveleal the cab files.
Some [newer] versions of these Features on Demand are compatible with other Windows Versions too as noted by the download special instructions in the Business Center.
• Features on Demand released with Windows 10, version 1903 are also compatible with version 1909 media.
• Features on Demand released with Windows 10, version 2004 are also compatible with version 20H2 and version 21H1 media.
Now that we have created a local repository (it is just a shared folder of all of these .cab files), we can now use Group Policy to specify the location for the clients to download and install from.
Computer Configuration > Policies > Administrative Templates >System > Specify settings for optional component installation and component repair
Set it to Enabled
Alternate source file path: \\SERVER.DOMAIN.LOCAL\SHARE\sources\sxs
Never attempt to download payload from Windows Update: Enabled/Checked
Download repair content and optional features directly from Windows Update instead of Windows Server Update Services (WSUS): Disabled/Unchecked
Note: It is recommended that you use the FQDN over just the hostname for name resolution. If you need to use multiple locations because you have multiple versions required, you can specify semi-colon separated paths: \\SERVER.DOMAIN.LOCAL\SHARE\1903\sources\sxs;\\SERVER.DOMAIN.LOCAL\SHARE\2004\sources\sxs;\\SERVER.DOMAIN.LOCAL\SHARE\Server\sources\sxs
You can now use the following PowerShell to install in this example, .NET 3.5 on a computer. This will try adding the Optional Components from the location specified in the policies.
if ($(Get-WindowsCapability -Online -Name "NetFX3~~~~").State -eq "Installed") {
Write-Output ".NET v3.5 is already installed."
}
else {
Try {
Add-WindowsCapability -Online -Name "NetFX3~~~~"
Write-Output ".NET v3.5 is now installed."
}
Catch {
Write-Output "Error in installing .NET v3.5."
Write-Output "Verify that the following GPO is setup."
Write-Output "Computer Configuration > Policies > Administrative Templates > System > Specify settings for optional component installation and component repair : Enabled"
Write-Output "Download repair content and optional features directly from Windows Update instead of Windows Server Update Services (WSUS) : Enabled/Checked"
Write-Output "Or if you prefer to use a local repository:"
Write-Output "Computer Configuration > Policies > Administrative Templates > System > Specify settings for optional component installation and component repair : Enabled"
Write-Output "Alternate source file path: \\SERVER.DOMAIN.LOCAL\SHARE\sources\sxs"
Write-Output "Never attempt to download payload from Windows Update: Enabled/Checked"
Write-Output "Download repair content and optional features directly from Windows Update instead of Windows Server Update Services (WSUS) : Disabled/Unchecked"
Write-Output ""
Write-Output $_.Exception
Write-Error -Exception $_.Exception
}
}
What if you just want to install it without changing Group Policies?
You can also specify the source inside of the PowerShell code so that you don’t have to touch Group Policies.
if ($(Get-WindowsCapability -Online -Name "NetFX3~~~~").State -eq "Installed") {
Write-Output ".NET v3.5 is already installed."
}
else {
Try {
Enable-WindowsOptionalFeature -Online -FeatureName NetFx3 -Source '\\server.domain.local\share\sources\sxs'
Write-Output ".NET v3.5 is now installed."
}
Catch {
Write-Output "Error in installing .NET v3.5."
Write-Output $_.Exception
Write-Error -Exception $_.Exception
}
}