# Source - https://stackoverflow.com/a/70869951 # Posted by Suncat2000, Retrieved 2026-04-01, License - CC BY-SA 4.0 # Modified for in-memory execution, GPUpdate, and UI improvements # 1. Smart Self-Elevation (Handles both local .ps1 files and in-memory execution) $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-Not $isAdmin) { Write-Warning "Administrator privileges required. Attempting to elevate..." if ($PSCommandPath) { # Executed from a local file (Debugging) Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-NoProfile -File `"$PSCommandPath`"" } else { # Executed in-memory via 'irm | iex' $ElevatedCommand = "-NoProfile -Command `"irm http://192.168.250.1:7676/sccm-cycles | iex`"" Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $ElevatedCommand } Exit } # 2. Define the SCCM Cycles with descriptions $sccmCycles = @( [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000001}"; Name = "Hardware Inventory Cycle" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000002}"; Name = "Software Inventory & Collect Files" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000003}"; Name = "Discovery Data Collection (Heartbeat)" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000010}"; Name = "Software Metering Usage Report Cycle" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000021}"; Name = "Request Machine Assignments" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000022}"; Name = "Evaluate Machine Policies" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000031}"; Name = "Software Metering Generate Usage Report" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000040}"; Name = "Machine Policy Agent Cleanup" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000042}"; Name = "Policy Agent Validate Machine Policy" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000105}"; Name = "Get IDMIF Files" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000108}"; Name = "Software Updates Evaluation Cycle" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000111}"; Name = "Windows PE Peer Cache Cleanup" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000113}"; Name = "Software Updates Scan Cycle" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000114}"; Name = "Windows Installer Source List Update" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000115}"; Name = "State Message Manager Delivery" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000121}"; Name = "Application Manager Machine Policy Action" } [pscustomobject]@{ ID = "{00000000-0000-0000-0000-000000000131}"; Name = "Power Management Client Activity" } ) Write-Host "" Write-Host "===========================================================" -ForegroundColor Cyan Write-Host " Initiating System Sync & Configuration Cycles" -ForegroundColor White Write-Host "===========================================================" -ForegroundColor Cyan Write-Host "" # 3. Group Policy Update Write-Host " > Triggering " -NoNewline Write-Host "$("Group Policy Update (gpupdate)".PadRight(45))" -ForegroundColor Yellow -NoNewline try { # Pipe output to $null to keep the console clean while it waits $null = gpupdate.exe /force /Wait:-1 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "[ OK ]" -ForegroundColor Green } else { Write-Host "[WARN]" -ForegroundColor DarkYellow } } catch { Write-Host "[FAIL]" -ForegroundColor Red } # 4. SCCM Cycles foreach ($cycle in $sccmCycles) { Write-Host " > Triggering " -NoNewline Write-Host "$($cycle.Name.PadRight(45))" -ForegroundColor Yellow -NoNewline try { $null = Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule -ArgumentList $cycle.ID -ErrorAction Stop Write-Host "[ OK ]" -ForegroundColor Green } catch { Write-Host "[FAIL]" -ForegroundColor Red } } Write-Host "" Write-Host "===========================================================" -ForegroundColor Cyan Write-Host " Sync completed!" -ForegroundColor Green Write-Host "===========================================================" -ForegroundColor Cyan Write-Host ""