共用方式為


Verifying Configuration Manager Backup Task with Windows PowerShell

A seemingly simple requirement for a Desired Configuration Management configuration item is to verify that the Configuration Manager 2007 site backup maintenance task is enabled.  What became the difficult part of this was tracking down the specific location in WMI that this data exists.  I have to give credit to Jamie Moyer for pointing me in the right direction.

Function Get-SccmBackupEnabled {

    # Refresh the site control file
    Invoke-WmiMethod -Path SMS_SiteControlFile -Name RefreshSCF -ArgumentList $sccmSiteCode -Computername $sccmServer -Namespace $sccmNamespace | Out-Null

    # Get the backup task object for this site
    $bkTask = Get-WmiObject -Query "SELECT * FROM SMS_SCI_SQLTask WHERE SiteCode = '$sccmSiteCode' AND ItemName = 'Backup SMS Site Server'" -Computername $sccmServer -Namespace $sccmNamespace

    If ( -not $bkTask ) { $False }
    ElseIf ( $bkTask.On -eq 'True' ) { $True }
    Else { $False }
}

The key here is the SMS_SCI_SQLTask WMI class, not SMS_SCI_MaintenanceTask as I originally suspected.

This cannot be used as-is in DCM; it must be paired with some code to first create the connection to the site server and then call this function.  I use Michael Niehaus’ PowerShell module which works very nicely for many common Configuration Manager automation tasks including the initial connection (New-SCCMConnection).

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .