Wednesday, November 14, 2018


PowerShell - SCCM Set Max Execution Time on Software Update Group

#Load Configuration Manager PowerShell Module
Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')

#Get SiteCode and set Powershell Drive
$SiteCode = Get-PSDrive -PSProvider CMSITE

Set-location $SiteCode":"

$start = Get-Date
$cmsugs = Get-CMSoftwareUpdate -UpdateGroupName "Server-2018" -Fast | Select CI_ID, LocalizedDisplayName, MaxExecutionTime, LocalizedCategoryInstanceNames # | ft -AutoSize
$count = 0
Foreach ($SoftwareUpdate in $cmsugs){
    if($SoftwareUpdate.MaxExecutionTime -ne 10800)    {
    $count += 1
        #$SoftwareUpdate
        Set-CMSoftwareUpdate -Id $SoftwareUpdate.CI_ID -MaximumExecutionMins 180
    }
}
$finish = Get-Date
$seconds = ($finish - $start).TotalSeconds 
$report =  "count: "+ $count + " " + $start + ", " + $finish + ", " + $seconds + " " + "Ave: " + $seconds/$count
write-host  $report

No comments:

Post a Comment