none
Trigger baseline evaluation

    Question

  • Hello,

    I have the following PowerShell script to trigger the baseline evaluation.

    $ComputerName = "HI22169"

    $Baselines = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration
    echo $Baselines
    $Baselines | % { ([wmiclass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration").TriggerEvaluation($_.Name, $_.Version) 

    I can get the baseline information with Get-WmiObject, but when i call the TriggerEvaluation method, the script failed with the following error:

    Exception calling "TriggerEvaluation" : ""
    At C:\Users\Administrator\Desktop\Automatisatie Scripts\Mijnscript_V1_remBaseline.
    ps1:14 char:18
    + $Baselines | % { ([wmiclass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfigurati
     ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : WMIMethodException

    Also when i hard code the name and the version of the baseline into the TriggerEvaluation method, it failed with the same error.

    Any help will be appreciated.

    Tanks, Mick

    Thursday, April 11, 2013 9:21 AM

Answers

  • I managed to get the script working working by changing it to this:

    $ComputerName = "<computername>"
     $Baselines = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration
     echo $baselines
    
     $name = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration | Where-Object {$_.DisplayName -match "<baselineName>"} | Select-Object -ExpandProperty Name
     write-host $name 
    
     $version = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration | Where-Object {$_.DisplayName -match "<baselineName>"} | Select-Object -ExpandProperty Version
     Write-Host $version
    
     $MC = [WmiClass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration"
     Write-Host $MC
    
     $Method = "TriggerEvaluation"
     $InParams = $mc.psbase.GetMethodParameters($Method)
     $InParams.IsEnforced = $true
     $InParams.IsMachineTarget = $false
     $InParams.Name = "$name"
     $InParams.Version = "$version"
     $inparams.PSBase.properties | select Name,Value | format-Table
     $R = $MC.InvokeMethod($Method, $InParams, $null)
     $R | Format-Table

    • Marked as answer by MickVR Friday, April 12, 2013 7:23 AM
    Friday, April 12, 2013 7:23 AM

All replies

  • I managed to get the script working working by changing it to this:

    $ComputerName = "<computername>"
     $Baselines = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration
     echo $baselines
    
     $name = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration | Where-Object {$_.DisplayName -match "<baselineName>"} | Select-Object -ExpandProperty Name
     write-host $name 
    
     $version = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration | Where-Object {$_.DisplayName -match "<baselineName>"} | Select-Object -ExpandProperty Version
     Write-Host $version
    
     $MC = [WmiClass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration"
     Write-Host $MC
    
     $Method = "TriggerEvaluation"
     $InParams = $mc.psbase.GetMethodParameters($Method)
     $InParams.IsEnforced = $true
     $InParams.IsMachineTarget = $false
     $InParams.Name = "$name"
     $InParams.Version = "$version"
     $inparams.PSBase.properties | select Name,Value | format-Table
     $R = $MC.InvokeMethod($Method, $InParams, $null)
     $R | Format-Table

    • Marked as answer by MickVR Friday, April 12, 2013 7:23 AM
    Friday, April 12, 2013 7:23 AM
  • I found that the best way is a combination of both - the original, and your answer.

    The original only works when the baseline is a machine-level baseline, and your answer only works when it's NOT a machine-level.

    So I did the following:

    $ComputerName = $env:COMPUTERNAME

    $Baselines = Get-WmiObject -ComputerName $ComputerName -Namespace root\ccm\dcm -Class SMS_DesiredConfiguration

    $MC = [WmiClass]"\\$ComputerName\root\ccm\dcm:SMS_DesiredConfiguration"

    $Method = "TriggerEvaluation"

    $InParams = $mc.psbase.GetMethodParameters($Method)

    $InParams.IsEnforced = $true

    $InParams.IsMachineTarget = $false

    foreach($Baseline in $Baselines){

        if($Baseline.IsMachineTarget)

        {

            $R= ([wmiclass]"\\$env:ComputerName\root\ccm\dcm:SMS_DesiredConfiguration").TriggerEvaluation($Baseline.Name, $Baseline.Version)

        }

        else

        {

            $InParams.Name = $Baseline.name

            $InParams.Version = $Baseline.version

            $R = $MC.InvokeMethod($Method, $InParams, $null)

        }

    }





    • Edited by havens1515 Monday, June 11, 2018 8:18 PM
    Monday, June 11, 2018 8:15 PM