Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Robert-LTH/80aa55e8036e35e0ca83bd18a3c7d870 to your computer and use it in GitHub Desktop.
Save Robert-LTH/80aa55e8036e35e0ca83bd18a3c7d870 to your computer and use it in GitHub Desktop.
param(
[string]$BaselineName
)
$ErrorActionPreference = "Stop"
try {
$Params = @{
Namespace = 'ROOT\ccm\Policy\Machine\ActualConfig'
ClassName = 'CCM_DCMCIAssignment'
Property = 'AssignmentID','AssignmentName'
}
if ($BaselineName -ne 'All') {
$Params.Add('Filter',"AssignmentName LIKE '$($BaselineName)_%'")
}
$Assignment = Get-CimInstance @Params | Select-Object -Property AssignmentID,AssignmentName
if (-not $Assignment) {
Write-Host "No baseline with name '$BaselineName' was found."
return
}
$Assignment | ForEach-Object {
$Result = Invoke-CimMethod -Namespace root\ccm -ClassName SMS_Client -MethodName 'TriggerSchedule' -Arguments @{ sScheduleId = $_.AssignmentID }
if ($Result) {
Write-Host "Triggered evaluation of '$(($_.AssignmentName -split '_')[0])'"
}
else {
Write-Host "Failed to trigger evaluation of '$(($_.AssignmentName -split '_')[0])'"
}
}
} catch {
Write-Host "Something went wrong: $_"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment