Advertisement
Cogger

Force-Windows-Updates.ps1

Nov 10th, 2022
1,588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # ================ Windows Updates ================
  3. # Restrict Windows Update P2P only on the local network
  4.     New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization" -Name "Config" -EA SilentlyContinue
  5.     New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\WMI\AutoLogger\SQMLogger" -Name "Start" -Type DWord -Value 0 -Force -EA SilentlyContinue
  6. # Do not show me the Windows welcome experience after updates and occasionally
  7.     New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -Type DWord "SubscribedContent-310093Enabled" -Value 0 -Force -EA SilentlyContinue
  8. # Turn off featured SOFTWARE notifications through Windows Update
  9.     New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Type DWord "EnableFeaturedSoftware" -Value 0 -Force -EA SilentlyContinue
  10. # Delivery Optimization Settings
  11.     New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" -Type DWord "DownloadMode" -Value 0 -Force -EA SilentlyContinue
  12.     New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" -Type DWord "DODownloadMode" -Value 0 -Force -EA SilentlyContinue
  13.     New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings" -Type DWord "DownloadMode" -Value 0 -Force -EA SilentlyContinue
  14. # Turn off automatic download/install of store app updates
  15.     New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "WindowsStore" -EA SilentlyContinue
  16.     New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore" -Name "WindowsUpdate" -EA SilentlyContinue
  17.     New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" -Type DWord "AutoDownload" -Value 2 -Force -EA SilentlyContinue
  18. # Prevent using sign-in info to automatically finish setting up after an update
  19.     New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Type DWord "ARSOUserConsent" -Value 0 -Force -EA SilentlyContinue
  20. # Set automatic updates to download and intsall automatically
  21.     New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "WindowsUpdate" -EA SilentlyContinue
  22.     New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name "AU" -EA SilentlyContinue
  23.     New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name AUOptions -Value 3 -Force -EA SilentlyContinue
  24. # Disable Automatic Updates and re-install of pre-installed bloatware
  25.     New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft" -Name "WindowsStore" -EA SilentlyContinue
  26.     New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" -Name "AutoDownload" -Type DWord -Value  2 -Force -EA SilentlyContinue      #disable
  27. #    New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\WindowsStore" -Name "AutoDownload" -Type DWord -Value  4 -Force -EA SilentlyContinue       #enable
  28.     New-ItemProperty -Path "HKCU:\Control Panel\International\User Profile" -Name "HttpAcceptLanguageOptOut" -Type DWord -Value  1 -Force
  29.     New-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer" -Name "DisableNotificationCenter" -Type DWord -Value  1 -Force
  30.     New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\ImmersiveShell" -Name "UseActionCenterExperience" -Type DWord -Value 0 -Force -EA SilentlyContinue
  31.     New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideSCAHealth" -Type DWord -Value 0 -Force -EA SilentlyContinue
  32.     New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform" -Name "NoGenTicket" -Type DWord -Value  1 -Force -EA SilentlyContinue
  33.     New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR" -Name "AppCaptureEnabled" -Type DWord -Value 0 -Force -EA SilentlyContinue
  34.     New-ItemProperty -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_Enabled" -Type DWord -Value 0 -Force -EA SilentlyContinue
  35. # Enable driver offerings through Windows Update.
  36.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" -Name "PreventDeviceMetadataFromNetwork" -ErrorAction SilentlyContinue
  37.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" -Name "DontPromptForWindowsUpdate" -ErrorAction SilentlyContinue
  38.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" -Name "DontSearchWindowsUpdate" -ErrorAction SilentlyContinue
  39.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" -Name "DriverUpdateWizardWuSearchEnabled" -ErrorAction SilentlyContinue
  40.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name "ExcludeWUDriversInQualityUpdate" -ErrorAction SilentlyContinue
  41. # Disable automatic restart
  42.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoRebootWithLoggedOnUsers" -ErrorAction SilentlyContinue
  43.     Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "AUPowerManagement" -ErrorAction SilentlyContinue
  44. # Set automatic updates to not download and intsall automatically.
  45.     New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "WindowsUpdate" -ErrorAction SilentlyContinue
  46.     New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name "AU" -ErrorAction SilentlyContinue
  47.     New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name AUOptions -Value 3 -ErrorAction SilentlyContinue
  48.  
  49.  
  50. ##  Set up prerequisites to install  PSWindowsUpdate.
  51. ### We install the package NuGet as a prerequisite to intsall PSWindowsUpdate.
  52.         Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
  53.  
  54. ### We add PSGallery to the trusted installer to our reposistories list.
  55.         Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
  56.  
  57. ### We install the module PSWindowsUpdate.
  58.         Install-Module PSWindowsUpdate
  59.  
  60. ### We add Microsoft Windows as a valid Windows Update supplier, and auto confirm.
  61.         Add-WUServiceManager -ServiceID "7971f918-a847-4430-9279-4a52d1efe18d" -Confirm:$false
  62.  
  63.     #Define Title
  64.         $host.UI.RawUI.WindowTitle = "Update Windows"
  65.     #Define Function to set color
  66.         function color ($bc,$fc) {
  67.             $a = (Get-Host).UI.RawUI
  68.             $a.BackgroundColor = $bc
  69.             $a.ForegroundColor = $fc ; cls}
  70.  
  71.     #Set color
  72.         color "DarkGray" "White"
  73.  
  74.     #Set size of console shell
  75.         cmd /c MODE con:cols=135 lines=30
  76.  
  77.     # Ensure that services are started
  78.         Start-Service -Name BITS
  79.         Start-Service -Name wuauserv
  80.         Start-Service -Name cryptSvc
  81.         Start-Service -Name msiserver
  82.  
  83.     # Run the script to install Windows Updates.
  84.         Write-Host('Searching, Downloading, and Installing Updates...')
  85.         Install-WindowsUpdate -AcceptAll -MicrosoftUpdate
  86.  
  87. # Reboot Confirmation Prompt, Yes, No, Cancel
  88. Add-Type -AssemblyName PresentationCore,PresentationFramework
  89. $msgBody = "Reboot the computer now?"
  90. $msgTitle = "Confirm Reboot"
  91. $msgButton = 'YesNoCancel'
  92. $msgImage = 'Warning'
  93. $Result = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage)
  94. Write-Host "The user chose: $Result [" ($result).value__ "]"
  95.  
  96.     If ($Result -eq '6') {
  97.             shutdown -r -c " " -t 15
  98.                          }
  99.  
  100.     If ($Result -eq '7') {
  101.             shutdown -a
  102.                          }
  103.  
  104.     If ($Result -eq '2') {
  105.             Write-Host 'Cancel Action Chosen'
  106.                          }
  107.  
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement