Skip to content

Commit 024fc02

Browse files
authoredApr 19, 2024
Update Trigger-Schedule.ps1
1 parent d6871ed commit 024fc02

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed
 

‎AD/Trigger-Schedule.ps1

+46-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
.NOTES
1818
https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/client-classes/triggerschedule-method-in-class-sms_client
1919
https://stackoverflow.com/a/63916401/8315671
20+
https://www.manishbangia.com/initiate-sccm-client-actions-cmd-line/
2021
#>
22+
23+
#Requires -RunAsAdministrator
24+
2125
function Trigger-Schedule
2226
{
2327
[CmdletBinding()]
@@ -45,6 +49,7 @@ function Trigger-Schedule
4549
$All
4650
)
4751

52+
# https://learn.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/client-classes/triggerschedule-method-in-class-sms_client#parameters
4853
$SupportedSchedules = @{
4954
"AppDeployment" = "{00000000-0000-0000-0000-000000000121}"
5055
"DiscoveryData" = "{00000000-0000-0000-0000-000000000003}"
@@ -55,24 +60,24 @@ function Trigger-Schedule
5560
"SoftwareMeteringUsage" = "{00000000-0000-0000-0000-000000000031}"
5661
"SoftwareUpdates" = "{00000000-0000-0000-0000-000000000108}"
5762
"SoftwareUpdatesScan" = "{00000000-0000-0000-0000-000000000113}"
63+
"PolicyAgentRequestAssignment" = "{00000000-0000-0000-0000-000000000026}"
5864
"UserPolicyRetrievalEvalCycle" = "{00000000-0000-0000-0000-000000000027}"
5965
"WindowsInstallerSourceListUpdate" = "{00000000-0000-0000-0000-000000000032}"
6066
}
6167

68+
$SID = (Get-CimInstance -Namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
69+
6270
foreach ($Schedule in $Schedules)
6371
{
64-
if ($Schedule -eq "UserPolicyRetrievalEvalCycle") # "Policy Agent Request Assignment" too
65-
{
66-
Write-Verbose -Message $SupportedSchedules[$Schedule] -Verbose
72+
Write-Verbose -Message $SupportedSchedules[$Schedule] -Verbose
6773

68-
$SID = (Get-CimInstance -Namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
74+
if (($Schedule -eq "PolicyAgentRequestAssignment") -or ($Schedule -eq "UserPolicyRetrieval"))
75+
{
6976
$ActualConfig = Get-WmiObject -ClassName CCM_Scheduler_ScheduledMessage -Namespace root\ccm\Policy\$SID\ActualConfig | Where-Object -FilterScript {$_.ScheduledMessageID -eq $SupportedSchedules[$Schedule]}
7077
$ActualConfig.Triggers = @('SimpleInterval;Minutes=1;MaxRandomDelayMinutes=0')
7178
$ActualConfig.Put()
7279

73-
Start-Sleep -Seconds 10
74-
75-
# $SID = (Get-CimInstance -namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
80+
# $SID = (Get-CimInstance -Namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
7681
# $ActualConfig = Get-CimInstance -Namespace root\ccm\Policy\$SID\ActualConfig -ClassName CCM_Scheduler_ScheduledMessage | Where-Object -FilterScript {$_.ScheduledMessageID -eq $Schedule}
7782
# $ActualConfig.Triggers = @('SimpleInterval;Minutes=1;MaxRandomDelayMinutes=0')
7883
# $ActualConfig | Set-CimInstance
@@ -90,15 +95,12 @@ function Trigger-Schedule
9095
{
9196
Write-Verbose -Message $Schedule -Verbose
9297

93-
if ($Schedule -eq "{00000000-0000-0000-0000-000000000027}") # "Policy Agent Request Assignment" too
98+
if (($Schedule -eq "PolicyAgentRequestAssignment") -or ($Schedule -eq "UserPolicyRetrieval"))
9499
{
95-
$SID = (Get-CimInstance -Namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
96100
$ActualConfig = Get-WmiObject -ClassName CCM_Scheduler_ScheduledMessage -Namespace root\ccm\Policy\$SID\ActualConfig | Where-Object -FilterScript {$_.ScheduledMessageID -eq $Schedule}
97101
$ActualConfig.Triggers = @('SimpleInterval;Minutes=1;MaxRandomDelayMinutes=0')
98102
$ActualConfig.Put()
99103

100-
Start-Sleep -Seconds 10
101-
102104
# $SID = (Get-CimInstance -Namespace root\ccm -ClassName CCM_UserLogonEvents | Where-Object -FilterScript {$null -eq $_.LogoffTime}).UserSID.Replace("-", "_")
103105
# $ActualConfig = Get-CimInstance -ClassName CCM_Scheduler_ScheduledMessage -Namespace root\ccm\Policy\$SID\ActualConfig | Where-Object -FilterScript {$_.ScheduledMessageID -eq $Schedule}
104106
# $ActualConfig.Triggers = @('SimpleInterval;Minutes=1;MaxRandomDelayMinutes=0')
@@ -107,9 +109,41 @@ function Trigger-Schedule
107109
else
108110
{
109111
Invoke-CimMethod -Namespace root\ccm -ClassName SMS_Client -MethodName TriggerSchedule -Arguments @{sScheduleID = $Schedule}
112+
}
113+
}
110114

111-
Start-Sleep -Seconds 10
115+
<#
116+
$SupportedSchedules = (Get-CimInstance -ClassName CCM_Scheduler_ScheduledMessage -namespace "ROOT\ccm\policy\machine\actualconfig" | Where-Object -FilterScript {$_.ScheduledMessageID -like "{00000000-0000-0000-0000-*}"}).ScheduledMessageID
117+
foreach ($SupportedSchedule in $SupportedSchedules)
118+
{
119+
try
120+
{
121+
Invoke-CimMethod -Namespace root\ccm -ClassName SMS_Client -MethodName TriggerSchedule -Arguments @{sScheduleID = $SupportedSchedule} -ErrorAction Stop
122+
"$SupportedSchedule success"
123+
}
124+
catch [Microsoft.Management.Infrastructure.CimException]
125+
{
126+
"$SupportedSchedule failed"
112127
}
113128
}
129+
#>
114130
}
115131
}
132+
<#
133+
$Schedules = @(
134+
"AppDeployment",
135+
"DiscoveryData",
136+
"FileCollection",
137+
"HardwareInventory",
138+
"MachinePolicyRetrieval",
139+
"SoftwareInventory",
140+
"SoftwareMeteringUsage",
141+
"SoftwareUpdates",
142+
"SoftwareUpdatesScan",
143+
"PolicyAgentRequestAssignment",
144+
"UserPolicyRetrievalEvalCycle",
145+
"WindowsInstallerSourceListUpdate"
146+
)
147+
Trigger-Schedule -Schedules $Schedules
148+
#>
149+
Trigger-Schedule -All

0 commit comments

Comments
 (0)