-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPauseUpdates-enable.ps1
More file actions
38 lines (33 loc) · 2.26 KB
/
PauseUpdates-enable.ps1
File metadata and controls
38 lines (33 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Check for admin privileges
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "This script requires administrative privileges. Please run as Administrator." -ForegroundColor Red
exit
}
# Logging function
$logFile = "PauseWindowsUpdate.log"
function Write-Log {
param($Message, $Color = "White")
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp - $Message" | Out-File -FilePath $logFile -Append
Write-Host "$timestamp - $Message" -ForegroundColor $Color
}
# Check GPO interference
$gpoSettings = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\Settings" -ErrorAction SilentlyContinue
if ($gpoSettings -and ($gpoSettings.PausedQualityStatus -eq 0 -or $gpoSettings.PausedFeatureStatus -eq 0)) {
Write-Log "Group Policy may override pause settings. Check with your administrator." -Color Yellow
}
# Pause update date
New-Item -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy" -Name "Settings" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\Settings" -Name "PausedQualityStatus" -Value 1 -Type DWord
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\Settings" -Name "PausedFeatureStatus" -Value 1 -Type DWord
#$startDate = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")
#$endDate = "2099-11-11T00:01:01Z"
$startDate = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
$endDate = "2099-11-11T00:01:01.000Z"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseQualityUpdatesStartTime" -Value $startDate
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseQualityUpdatesEndTime" -Value $endDate
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseFeatureUpdatesStartTime" -Value $startDate
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseFeatureUpdatesEndTime" -Value $endDate
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "PauseUpdatesExpiryTime" -Value $endDate
Write-Log "Windows Updates paused until $endDate" -Color Green