Skip to content

Instantly share code, notes, and snippets.

@jmconway
Created May 10, 2021 15:37
Show Gist options
  • Save jmconway/e7aff7ec6f196a90fe374a937092df61 to your computer and use it in GitHub Desktop.
Save jmconway/e7aff7ec6f196a90fe374a937092df61 to your computer and use it in GitHub Desktop.
A PowerShell script I used to enable Remote Server Administration Tools on secure management workstations. First there's a function to clear our prior WSUS implementation, so one may want to cut that part out if it's not applicable to their environment. Next there's a function to allow getting components/optional features from Windows Update. Fi…
# Now that we don't run our own WSUS, clear WSUS config from registry if causing conflicts.
function Clear-WSUSConfig {
Stop-Service wuauserv -force
Set-ItemProperty -Path HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWUServer -Value 0
Start-Service wuauserv
}
# Any errors encountered even when running as admin usually require manually changing Windows Update/Component servicing settings
# Use registry instead of manually editing local Group Policy setting "Specify settings for optional component installation and component repair"
# https://admx.help/?Category=Windows_10_2016&Policy=Microsoft.Policies.Servicing::Servicing
function Set-WUServicing {
$rootPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\"
$regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing"
$regName = "RepairContentServerSource"
$regValue = "2"
if (!(Test-Path -Path $regPath)) {
New-ItemProperty -Path $rootPath -Name "Servicing"
}
Set-ItemProperty -Path $regPath -Name $regName -Type DWORD -Value $regValue -Force
}
Try {
Clear-WSUSConfig
} Catch {
Write-Error -Message "ERROR: Problem with Windows Update service OR failed to set registry UseWUServer value to 0."
}
Try {
Set-WUServicing
} Catch {
Write-Error -Message "ERROR: failed to set registry RepairContentServerSource value to 2."
}
$tools = "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0","Rsat.DHCP.Tools~~~~0.0.1.0","Rsat.FileServices.Tools~~~~0.0.1.0","Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0","Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0","Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0","Rsat.ServerManager.Tools~~~~0.0.1.0"
foreach ($tool in $tools) {
Add-WindowsCapability -Online -Name $tool -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment