Tuesday, 14 August 2012

PowerShell - Invoke SCCM DCM rule evaluation remotely.

Here at the company I contract too we use SCCM DCM to maintain a base list of hotfixes on our SCCM site servers. Whilst installing a new set of additional hotfixes I needed a quick and easy way to remotely update the DCM compliance state for any given server. Below is a PowerShell module I found and modified to perform this task easily. I have also gone one step further and added it into an SCCM.psm1 module which I use a profile script to load whenever I open the PS shell so the command is always available for use.

Note: The Return code 0 indicated the DCM baseline evaluation has been triggered successfully.



function Invoke-SCCMDCMEvaluation
{
    param (
        [Parameter(Mandatory=$true, HelpMessage="Computer Name",ValueFromPipeline=$true)] $ComputerName
           )
    $Baselines = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration
    $Baselines | % { ([wmiclass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration").TriggerEvaluation($_.Name, $_.Version) }
}

Invoke-SccmBaselineEvaluation localhost

4 comments:

  1. Hello,
    I’m quite new to scripting for SCCM and I’m having an issue with your script.
    When I run the script I get the information about the baselines, but the “TriggerEvaluation” always fails with the following error:

    Exception calling "TriggerEvaluation" : ""
    At D:\Users\Administrator.TESTMACHINE_2\Desktop\AD.ps1:3 char:104
    + $Baselines | % { ([wmiclass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration").TriggerEvaluation <<<< ($_.Name
    , $_.Version) }
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WMIMethodException

    Do you have any ideas?

    Thanks

    ReplyDelete
  2. great script, saved me a bundle of time. Thanks

    ReplyDelete
  3. Worked for me. When you invoke the function, make sure to use: 'Invoke-SCCMDCMEvaluation localhost', the invoke command listed after the function above is incorrect.

    ReplyDelete
  4. Thank you for the script. Works perfectly.

    ReplyDelete