Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This will trigger the Configuration Baseline based on a parameter.
#For using in "Run Script" Node. Has Exit At end... will exit your ISE if you run in ISE. :-)
#Adopted from another script, so it has some Write-Hosts that don't really make sense in a CI, deal with it.
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
$BaselineName="WaaS Pre-Assessment"
)
#Invoke Machine Policy
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLWIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000021}" | Out-Null
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000022}" | Out-Null
Start-Sleep -Seconds 120
#Get Baseline Info
$DCM = [WMIClass] "ROOT\ccm\dcm:SMS_DesiredConfiguration"
$WaaSBaseline = Get-WmiObject -Namespace root\ccm\dcm -QUERY "SELECT * FROM SMS_DesiredConfiguration WHERE DisplayName LIKE ""$BaselineName""" -ErrorAction SilentlyContinue
#Display Baseline Info
#Trigger Baseline Status:
if ($WaaSBaseline -ne $null)
{
$DCM.TriggerEvaluation($WaaSBaseline.Name, $WaaSBaseline.Version) | Out-Null
Start-Sleep -Seconds 120
$WaaSBaseline = Get-WmiObject -Namespace root\ccm\dcm -QUERY "SELECT * FROM SMS_DesiredConfiguration WHERE DisplayName LIKE ""$BaselineName"""
$LastEvalTime = $WaaSBaseline.LastEvalTime
if ($LastEvalTime -ne $Null -and $LastEvalTime -notlike "000*" )
{
$LastEvalString = $LastEvalTime.Substring(0,14)
#$LastEvalString = [MATH]::Round($LastEvalString)
#$LastEvalString = $LastEvalString.ToString()
$LastEvalString = [DateTime]::ParseExact($LastEvalString,"yyyyMMddHHmmss",$null)
$EvalDifference = New-TimeSpan -End ([System.DateTime]::UtcNow) -Start $LastEvalString
$EvalDifferenceHours = $EvalDifference.TotalHours
$UserReport = $DCM.GetUserReport($WaaSBaseline.Name,$WaaSBaseline.Version,$null,0)
[XML]$Details = $UserReport.ComplianceDetails
$WaaSNonCompliant = $Details.ConfigurationItemReport.ReferencedConfigurationItems.ConfigurationItemReport | Where-Object {$_.CIComplianceState -eq "NonCompliant"}
if ($Details.ConfigurationItemReport.CIComplianceState -eq "Compliant")
{
$BaselineStatus = "Compliant"
Write-OutPut "Baseline Status: $BaselineStatus"
}
Else
{
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000021}" | Out-Null
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000022}" | Out-Null
Start-Sleep -Seconds 180
$DCM.TriggerEvaluation($WaaSBaseline.Name, $WaaSBaseline.Version) | Out-Null
Start-Sleep -Seconds 300
$WaaSBaseline = Get-WmiObject -Namespace root\ccm\dcm -QUERY "SELECT * FROM SMS_DesiredConfiguration WHERE DisplayName LIKE ""$BaselineName"""
$WaaSNonCompliant = $Details.ConfigurationItemReport.ReferencedConfigurationItems.ConfigurationItemReport | Where-Object {$_.CIComplianceState -eq "NonCompliant"}
$BaselineStatus = "NonCompliant"
$UserReport = $DCM.GetUserReport($WaaSBaseline.Name,$WaaSBaseline.Version,$null,0)
[XML]$Details = $UserReport.ComplianceDetails
if ($Details.ConfigurationItemReport.CIComplianceState -eq "Compliant")
{
$BaselineStatus = "Compliant"
Write-OutPut "Baseline Status: $BaselineStatus"
}
Else
{
Write-OutPut "Baseline Status:: $BaselineStatus"
$NonCompliantNames = ForEach ($PA_Rule in $WaaSNonCompliant)
{($PA_Rule).CIProperties.Name.'#text'}
ForEach ($PA_Rule in $WaaSNonCompliant)
{
Write-OutPut "Rule: $($PA_Rule.CIProperties.Name.'#text')"
}
#Write-OutPut"NonCompliant Items: $WaaSNonCompliant" -ForegroundColor Red
$DCM.TriggerEvaluation($WaaSBaseline.Name, $WaaSBaseline.Version) | Out-Null
}
}
}
Else
{
$BaselineStatus = "No Status"
Write-OutPut "Baseline Status: $BaselineStatus"
$DCM.TriggerEvaluation($WaaSBaseline.Name, $WaaSBaseline.Version) | Out-Null
}
}
Else {Write-Output "No baseline named $BaselineName"}
#Invoke Hardware Inventory Delta
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000001}" | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.