#
# Script to switch Windows Update Service and change WSUS server
# Author: LookBack
# Date: 2017-05-05_172630
#
Clear-Host
Write-Host "0 -> 修改Windows更新為系統默認設置(后期將導致系統無法更新)"
Write-Host "1 -> 關閉Windows更新和檢查更新"
Write-Host "2 -> 修改Windows更新為-通知下載并通知安裝-使用內網源"
Write-Host "3 -> 修改Windows更新為-自動下載并通知安裝-使用內網源"
Write-Host "4 -> 修改Windows更新為-自動下載并安排安裝-使用內網源"
Write-Host "按任意鍵退出..."
Write-Host
switch(Read-Host "選擇Windows更新設置"){
0 {$UpdateValue = 0}
1 {$UpdateValue = 1}
2 {$UpdateValue = 2}
3 {$UpdateValue = 3}
4 {$UpdateValue = 4}
Default{Exit}
}
$WindowsUpdatePath = "HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\"
$AutoUpdatePath = "HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
function LocalUpdateServer() {
Set-ItemProperty -Path $WindowsUpdatePath -Name AcceptTrustedPublisherCerts -Value 1
Set-ItemProperty -Path $WindowsUpdatePath -Name UpdateServiceUrlAlternate -Value "http://10.10.240.50:8530"
Set-ItemProperty -Path $WindowsUpdatePath -Name WUServer -Value "http://10.10.240.50:8530"
Set-ItemProperty -Path $WindowsUpdatePath -Name WUStatusServer -Value "http://10.10.240.50:8530"
}
If(Test-Path -Path $WindowsUpdatePath) {
Remove-Item -Path $WindowsUpdatePath -Recurse
}
If ($UpdateValue -gt 0) {
$null = New-Item -Path $WindowsUpdatePath
$null = New-Item -Path $AutoUpdatePath
}
if ($UpdateValue -gt 1) {
Set-ItemProperty -Path $AutoUpdatePath -Name NoAutoUpdate -Value 0
Set-ItemProperty -Path $AutoUpdatePath -Name ScheduledInstallDay -Value 0
}
If ($UpdateValue -eq 1) {
Set-ItemProperty -Path $AutoUpdatePath -Name NoAutoUpdate -Value 1
}
If ($UpdateValue -eq 2) {
LocalUpdateServer
Set-ItemProperty -Path $AutoUpdatePath -Name AUOptions -Value 2
Set-ItemProperty -Path $AutoUpdatePath -Name ScheduledInstallTime -Value 3
}
If ($UpdateValue -eq 3) {
LocalUpdateServer
Set-ItemProperty -Path $AutoUpdatePath -Name AUOptions -Value 3
Set-ItemProperty -Path $AutoUpdatePath -Name ScheduledInstallTime -Value 3
}
If ($UpdateValue -eq 4) {
$null = LocalUpdateServer
Set-ItemProperty -Path $AutoUpdatePath -Name AUOptions -Value 4
Set-ItemProperty -Path $AutoUpdatePath -Name ScheduledInstallTime -Value 3
}
Write-Host
Write-Host '執行完畢,按任意鍵退出...'
Read-Host
由于powershell操作注冊表有權限限制,上面的腳本還需要配合下面的腳本才可以實現右鍵以管理員身份運行的目的
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\runas]
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\runas\command]
@="powershell.exe \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""





















