PowerShell
Edit|Remove
param ( $VMMServer="localhost",  
        $DomainUser="xxx",  
        $Password="yyy") 
 
$scriptdir="c:\scvmm\UpdateAutomation" 
$scriptout=$scriptdir + "\Output" 
$logfile="VMMUpdateServerSync" + (Get-Date -Format "yyyyMMddHHmmss") 
 
. $scriptdir\VMMUpdateUtil.ps1 
 
$global:retFlag=0 
 
UpdateLogFile -message "***Update Server Sync Process*** <START>" -appendflag $false 
 
# Import VMM Module. 
if((Get-Module -Name "virtualmachinemanager"-eq $null) { 
      Import-Module "virtualmachinemanager"     
} 
$vmmspwd = ConvertTo-SecureString $Password -AsPlainText -Force 
$Credential = New-Object System.Management.Automation.PSCredential $DomainUser,$vmmspwd 
 
# Connect to the VMM server. 
$VMMServerObj=Get-SCVMMServer -ComputerName $VMMServer -Credential $Credential 
 
# Check Servicing Window time range 
$swName = "SWForUpdateSync" 
CheckCurrTimeInSW $swName 
if($retFlag -eq 1){ 
    $message="ERROR: The Current date/time is not in SW for Update Server Sync Return Code:" + $retFlag 
    UpdateLogFile $message 
    return 
} 
 
# Synchronize Update Server 
#$updtServer=$UpdateServer 
#SyncUpdateServer $updtServer 
SyncUpdateServer 
if($retFlag -eq 1){ 
    $message="Failed submitting job for Update Server Sync Return Code:" + $retFlag 
    UpdateLogFile $message 
    return 
} 
 
UpdateLogFile -message "***Update Server Sync Process*** <END>" -appendflag $true 
 
 

System Center Virtual Machine Manager (SCVMM) 2012 introduced two new features for managing updates for all VMM managed computers (Update Management) and
maintaining servicing window timings to schedule automated activities (through System Center Orchestrator or Windows Task Scheduler or other scheduler tools).
Here in this article, it explains the PowerShell scripts developed based on VMM cmdlets to automate the update process or patching of VMM managed computers by
leveraging the servicing window feature in SCVMM 2012 and SCORCH 2012.

 

The update process automation flow consists of the following four steps:

- Automating Update Server Synchronization in SCVMM 2012 (Part 1 of 4)

- Automating Baseline and Update List data from SCCM (Part 2 of 4)

- Automating Update Compliance Scan in SCVMM 2012 (Part 3 of 4)

- Automating Update Compliance Remediate in SCVMM 2012 (Part 4 of 4)

 

You can customize the steps (for example the ordering or skipping steps like SCCM integration) in a more flexible manner based on the requirement. Also the scripts are fully customizable as the sample scripts are developed based on the SCVMM 2012 cmdlets.

 

For each step a separate document is available describing the following items in detail.

SCVMM Environment Pre-requisite - Describes the SCVMM environment and setup requirement to run the PowerShell scripts.

PowerShell Script Reference - Describes the script files used for the automation step

Automation flow -Describes how the automation step is performed in detail

PowerShell Script Pre-requisite - Describes the PowerShell script requirement such as the directory to create and copy the files, etc.

Powershell Script - Parameter Options - Describes the parameter level options available to toggle/switch functions such as to force the Update Remediate process irrespective of whether the target machines are in Compliant or Non-Compliant state.

PowerShell Script Execution Types - Describes the various ways to execute the scripts - Choose the one that fits to the environment and to the needs

 

The document detail for each step is as described below:

- Automating Update Server Synchronization in SCVMM 2012.docx

- Automating Update Baseline from SCCM.docx

- Automating Update Compliance Scan in SCVMM 2012.docx

- Automating Update Compliance Remediate in SCVMM 2012.docx

 

The script detail for each step is as described below:

- VMMUpdateServerSync.ps1

- VMMUpdateBaselineFromSCCM.ps1

- VMMUpdateComplianceScan.ps1

- VMMUpdateComplianceRemediate.ps1

 

Other common scripts referred in the mainline scripts are as below:

VMMUpdateUtil.ps1 – Contains all the common SCVMM functions for the mainline scripts

SCCMUpdateUtil.ps1 - Contains all the common SCCM functions for the mainline scripts

 

The documents and scripts can be obtained from the attached zip file - SCVMM2012-UpdateAutomation-Docs-Scripts.zip