Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Last active August 30, 2025 15:42
Show Gist options
  • Select an option

  • Save nanoDBA/6dc0974d4ea7e275b5fb40df6cb6b545 to your computer and use it in GitHub Desktop.

Select an option

Save nanoDBA/6dc0974d4ea7e275b5fb40df6cb6b545 to your computer and use it in GitHub Desktop.
Exclude SQL Server From Windows Updates
<# https://4sysops.com/archives/use-powershell-to-test-if-a-windows-server-is-pending-a-reboot/ #> $pendingRebootTests=@(@{Name='RebootPending';Test={Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing' -Name 'RebootPending' -ErrorAction Ignore};TestType='ValueExists'},@{Name='RebootRequired';Test={Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' -Name 'RebootRequired' -ErrorAction Ignore};TestType='ValueExists'},@{Name='PendingFileRenameOperations';Test={Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name 'PendingFileRenameOperations' -ErrorAction Ignore};TestType='NonNullValue'}); $results=@();foreach($item in $pendingRebootTests){$result=Invoke-Command -ScriptBlock $item.Test;if($result){$results+=New-Object PSObject -Property @{Name=$item.Name;Status='Pending'}}};if($results){$results|Format-Table}else{Write-Output 'No Pending Reboot'}
<# DANGER - ***forced reboot(s) may occur*** #>
# $moduleName = "PSWindowsUpdate"
# if (Get-Module -ListAvailable -Name $moduleName) {
# Write-Output "$moduleName module is already installed." | Out-String | Write-Host -ForegroundColor Yellow
# Import-Module $moduleName
# }
# else {
# Write-Output "Module $moduleName is not installed - installing..." | Out-String | Write-Host -ForegroundColor Yellow
# $NuGetProvider = Get-PackageProvider -Name NuGet | Where-Object Version -GT 2.8.5.201; if ( -not $NuGetProvider) { Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false }
# <# Install moduleName #>Install-Module -Force $moduleName -Confirm:$false -Verbose
# Import-Module $moduleName
# }
<# DANGER - ***forced reboot(s) may occur*** #>
$paramHash = @{
AcceptAll = $True
Install = $True
NotTitle = 'SQL' <# Exclude SQL Server From Windows Updates #>
Verbose = $True
# Modify next line as desired
RootCategories = 'Security Updates','Critical Updates', 'Definition Updates' #, 'Drivers'
AutoReboot = $True
# AutoReboot = $false
Confirm = $True
}
Get-WindowsUpdate @paramHash -ShowPreSearchCriteria -MicrosoftUpdate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment