Skip to content

Instantly share code, notes, and snippets.

@realslacker
Created July 10, 2019 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realslacker/8321a8ec669c78e44a95e30d2638f46d to your computer and use it in GitHub Desktop.
Save realslacker/8321a8ec669c78e44a95e30d2638f46d to your computer and use it in GitHub Desktop.
<#PSScriptInfo
.VERSION 2019.3.25.900
.GUID cd6e3726-52d2-4ae0-b423-1d4d8853775f
.AUTHOR Shannon Graybrook
.COMPANYNAME Methode Electronics
.TAGS RSAT Windows10
#>
<#
.DESCRIPTION
Installs RSAT tools on Windows 10 by bypassing WSUS.
#>
Param()
# self-elevate the script if required
if ( -not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator') ) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
# get the current WSUS setting
$UseWUServerValue = Get-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWUServer -ErrorAction SilentlyContinue | Select-Object -ExpandProperty UseWUServer
# get current servicing settings
$LocalSourcePath = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name LocalSourcePath -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LocalSourcePath
$RepairContentServerSource = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -ErrorAction SilentlyContinue | Select-Object -ExpandProperty RepairContentServerSource
# if WSUS is turned on we turn it off temporarily
if ( $UseWUServerValue -eq 1 ) {
Write-Warning "Need to bypass WSUS for RSAT installation until MS releases RSAT to WSUS update channel."
Write-Warning "Changing HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\UseWUServer value from '1' to '0'"
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWUServer -Value 0
if ( $LocalSourcePath -eq $null ) {
New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Force -ErrorAction SilentlyContinue > $null
Write-Warning "Creating HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath with empty value."
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name LocalSourcePath -Value '' -Force > $null
$RemoveLocalSourcePathProperty = $true
} elseif ( $LocalSourcePath -ne '' ) {
Write-Warning ( "Setting HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath from '{0}' to empty value." -f $LocalSourcePath )
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name LocalSourcePath -Value '' -Force > $null
$ResetLocalSourcePathProperty = $true
}
if ( $RepairContentServerSource -eq $null ) {
New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Force -ErrorAction SilentlyContinue > $null
Write-Warning "Creating HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath with value of '2'."
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -Value 2 -PropertyType Dword -Force > $null
$RemoveRepairContentServerSource = $true
} elseif ( $RepairContentServerSource -ne 2 ) {
Write-Warning ( "Setting HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath from '{0} to '2'." -f $RepairContentServerSource )
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -Value 2 -Force > $null
$ResetRepairContentServerSource = $true
}
}
# get a list of RSAT tools that are not installed
$FeaturesToInstall = Get-WindowsCapability -Name RSAT* -Online | Where-Object State -eq 'NotPresent'
# if there are any that are not installed, install them
if ( $FeaturesToInstall.Count ) {
Write-Information "Installing RSAT tools..." -InformationAction Continue
$FeaturesToInstall | ForEach-Object {
Write-Information $_.DisplayName -InformationAction Continue
$_ | Add-WindowsCapability -Online > $null
}
} else {
Write-Information "All RSAT tools already reporting as installed." -InformationAction Continue
}
# turn back on WSUS if applicable
if ( $UseWUServerValue -eq 1 ) {
Write-Warning "Resetting UseWUServer value back to '1'"
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name UseWUServer -Value 1
if ( $RemoveLocalSourcePathProperty ) {
Write-Warning "Removing HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name LocalSourcePath -Force -Confirm:$false -ErrorAction SilentlyContinue
}
if ( $ResetLocalSourcePathProperty ) {
Write-Warning ( "Resetting HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\LocalSourcePath to '{0}'" -f $LocalSourcePath )
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name LocalSourcePath -Value $LocalSourcePath
}
if ( $RemoveRepairContentServerSource ) {
Write-Warning "Removing HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\RepairContentServerSource"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -Force -Confirm:$false -ErrorAction SilentlyContinue
}
if ( $ResetRepairContentServerSource ) {
Write-Warning ( "Resetting HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing\RepairContentServerSource '{0}'" -f $RepairContentServerSource )
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -Value $RepairContentServerSource
}
}
$null = Read-Host "Press ENTER to exit"
@pythoninthegrass
Copy link

pythoninthegrass commented Aug 1, 2019

Neat trick disabling WSUS via registry. Gonna file that away in the archives ;)

EDIT: using POSH that is. Normally go in and delete the key manually, then it gets reinstated by GPO an hour or so later.

@realslacker
Copy link
Author

Thanks, just figured it would be easier as a one step process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment