Created
July 4, 2018 08:15
-
-
Save DarkAllien/d06409fed2bcde265db18aa3dacd1fcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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