Reputation: 73
I wrote a function that I use to invoke all of the Configuration Manager Actions on remote devices. I noticed that all of the configuration manager actions can be invoked in a similar manner except for "User Policy Retrieval & Evaluation Cycle", at the time I did some research and it seemed like it was working, but has since began to throw errors.
When the script is iterating through the devices it always succeeds on the first device then fails on any following devices, but only for the User Policy Retrieval portion. If I try to run it locally/remotely on a single device it works fine.
The error I am receiving:
Cannot convert value "root\ccm\Policy\S_1_5_21_81564394_10899842_11037298_5564\ActualConfig:CCM_Scheduler_ScheduledMessage.ScheduledMessageID='{00000000-0000-0000-0000-000000000027}'" to type "System.Management.ManagementObject". Error: "Invalid namespace "
Function for initializing CM Actions:
Function Initialize-CMActions {
Write-Host "`tInitializing Configuration Manager Actions." -ForegroundColor Yellow
[System.Collections.ArrayList]$Actions = @(
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000121}";Name = "Application Deployment Evaluation Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000003}";Name = "Discovery Data Collection Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000001}";Name = "Hardware Inventory Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000021}";Name = "Machine Policy Retrieval & Evaluation Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000031}";Name = "Software Metering Usage Report Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000114}";Name = "Software Updates Deployment Evaluation Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000113}";Name = "Software Updates Scan Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000027}";Name = "User Policy Retrieval & Evaluation Cycle"},
[PSCustomObject]@{ID = "{00000000-0000-0000-0000-000000000032}";Name = "Windows Installer Source List Update Cycle"}
)
Foreach ($Action in $Actions)
{
#If Action is User Policy Retrieval
if ($Action.ID -eq "{00000000-0000-0000-0000-000000000027}")
{
Try
{
#Invoke User Policy Retrieval & Evaluation Cycle using sid S_1_5_21_81564394_10899842_11037298_5564
Invoke-command -ComputerName $($Workstation.SN) -ScriptBlock {
$sched=([wmi]"root\ccm\Policy\S_1_5_21_81564394_10899842_11037298_5564\ActualConfig:CCM_Scheduler_ScheduledMessage.ScheduledMessageID='{00000000-0000-0000-0000-000000000027}'")
$sched.Triggers=@('SimpleInterval;Minutes=1;MaxRandomDelayMinutes=0') | Out-Null;
$sched.Put() | Out-Null;
} -ErrorAction Stop
Write-Host "`t`tInitialized User Policy Evaluation Cycle" -ForegroundColor Green
}
Catch
{
Write-Host "`t`tUnable to initialize User Policy Retrieval & Evaluation Cycle for SID - S_1_5_21_81564394_10899842_11037298_5564" -ForegroundColor Red
Write-Host "$_"
}
}
Else
{
Try
{
Invoke-Command -ComputerName $($Workstation.SN) {Invoke-WmiMethod -namespace root\ccm -class sms_client -name TriggerSchedule $using:Action.ID | Out-Null}
Write-Host "`t`tInitialized $($Action.Name)" -ForegroundColor Green
}
Catch
{
Write-Host "`t`tUnable to initialize $($Action.Name)" -ForegroundColor Red
$_
}
}
}
}
Is there something in this function that I am missing causing a memory leak or variable mismatch? I normally like to figure out my mistakes on my own, but I have spent so many hours trying to figure this out and I can't seem to find any of the previous resources I used to piece together how to initialize the User Policy Retrieval & Evaluation Cycle.
All criticisms, insights, and answers are welcome!
Upvotes: 0
Views: 31