Skip to content

Instantly share code, notes, and snippets.

@DarkAllien
Created July 4, 2018 08:15
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 DarkAllien/d06409fed2bcde265db18aa3dacd1fcc to your computer and use it in GitHub Desktop.
Save DarkAllien/d06409fed2bcde265db18aa3dacd1fcc to your computer and use it in GitHub Desktop.
Function Installation_InProgress {
<#
.SYNOPSIS
The function will check if there are updates in progress
.DESCRIPTION
#>
$Installing = $False
$installing_app = $False
$SCCMUpdate = get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate" -namespace "ROOT\ccm\ClientSDK"
if (@($SCCMUpdate | Where-Object {($_.EvaluationState -ge 2 -and $_.EvaluationState -le 7) -or $_.EvaluationState -eq 11 }).length -ne 0) { $installing = $true } else { $installing = $false }
$SCCMApplication = get-wmiobject -query "SELECT * FROM CCM_Application" -namespace "ROOT\ccm\ClientSDK"
if (@($SCCMApplication | Where-Object {($_.EvaluationState -ge 5 -and $_.EvaluationState -le 12) -or $_.EvaluationState -eq 20}).length -ne 0) { $installing_app = $true } else { $installing_app = $false }
if ($installing_app -or $installing) {
return $true
}
else {
return $false
}
}
$time = Get-Date
$sql_reboot=(get-ItemProperty hklm:\SYSTEM\SCCM).SQL_Restart
#if no current software or update is installing and no pending reboot, install SQL updates
if (!(Installation_InProgress) -and ($sql_reboot -eq 1)) {
"$time - CI.SQL.Servers.Restart - Pending SQL updates requested reboot Found" | out-file "$env:windir\Logs\CB.SQL.Servers.Updates.log" -Append
return $false
}
else {
"$time - CI.SQL.Servers.Restart - Pending SQL updates Restart Conditions Not Met" | out-file "$env:windir\Logs\CB.SQL.Servers.Updates.log" -Append
return $true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment