Skip to content

Instantly share code, notes, and snippets.

@chdanielmueller
Created April 8, 2013 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chdanielmueller/5339015 to your computer and use it in GitHub Desktop.
Save chdanielmueller/5339015 to your computer and use it in GitHub Desktop.
Powershell Script referenced by http://behind-monitor.blogspot.com/ This script sets WSUS Keys to selected Policys. The script edits the existing "Computer Policy" GPO with the user specified settings. Requirements - Minimum Powershell Version 2.0 - Computer with RSAT or Domain Controller - User must have the necessary permissions to modify the …
<#
.SYNOPSIS
This Script sets WSUS Keys to selected Policys.
.DESCRIPTION
The script edits the existing "Computer Policy" GPO with the user specified settings.
Requirements
- Minimum Powershell Version 2.0
- Computer with RSAT or Domain Controller
- User must have the necessary permissions to modify the GPO.
.NOTES
FileName : SetWSUSPolicySettings.ps1
Version : 1.0
Author : Daniel Müller (chdanielmueller)
Last modified by : Daniel Müller (chdanielmueller)
.EXAMPLE
Psh> SetWSUSPolicySettings.ps1
#>
## Start Functions
# Enables Setting specified by ValueName at Key in Policy
Function EnableSetting
{
param($gpo, $key, $valueName)
$null = Set-GPRegistryValue -Name $gpo -Key $key -ValueName $valueName -Type DWORD -Value 1
if($?){Write-Host "The GPO value $valueName has been enabled for GPO $gpo." -foregroundcolor green}
else {Write-Host "The GPO value $valueName could not be enabled for GPO $gpo." -foregroundcolor red}
}
# Disables Setting specified by ValueName at Key in Policy
Function DisableSetting
{
param($gpo, $key, $valueName)
$null = Set-GPRegistryValue -Name $gpo -Key $key -ValueName $valueName -Type DWORD -Value 0
if($?){Write-Host "The GPO value $valueName has been disabled for GPO $gpo." -foregroundcolor green}
else {Write-Host "The GPO value $valueName could not be disabled for GPO $gpo." -foregroundcolor red}
}
# Sets Value to Setting specified by ValueName at Key in Policy
Function SetSetting
{
param($gpo, $key, $valueName, $value)
$null = Set-GPRegistryValue -Name $gpo -Key $key -ValueName $valueName -Type STRING -Value $value
if($?){Write-Host "The GPO value $valueName has been set to $value for GPO $gpo." -foregroundcolor green}
else {Write-Host "The GPO value $valueName could not be set to $value for GPO $gpo." -foregroundcolor red}
}
## End Functions
## Start Script
# Import Module
Import-Module GroupPolicy -cmdlet Set-GPRegistryValue
# Get User Informations
$wsusServer = Read-Host ("WSUS Server (eg. http://mustersrv0:8530)")
# Set Settings in Computer Policy
EnableSetting "Computer Policy" "HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" "UseWUServer"
SetSetting "Computer Policy" "HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate" "WUServer" $wsusServer
SetSetting "Computer Policy" "HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate" "WUStatusServer" $wsusServer
## End Script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment