Skip to content

Instantly share code, notes, and snippets.

@gwblok
Created May 29, 2020 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwblok/ad56603bef9a6845e4401c40187cc941 to your computer and use it in GitHub Desktop.
Save gwblok/ad56603bef9a6845e4401c40187cc941 to your computer and use it in GitHub Desktop.
$RestartProgram = Get-CimInstance -ClassName "CCM_SoftwareDistribution" -Namespace "ROOT\ccm\policy\machine\actualconfig" | Where-Object {$_.PKG_Name -match "Restart Computer" -and $_.PRG_ProgramName -match "Exit Force Restart"}
$RestartProgramDeployID = $RestartProgram.ADV_AdvertisementID
$RestartProgramPackageID = $RestartProgram.PKG_PackageID
$RestartProgramProgramID = $RestartProgram.PRG_ProgramID
[XML]$XML = $RestartProgram.PRG_Requirements
$Schedule = $xml.SWDReserved.ScheduledMessageID
$Program = ([wmi]"ROOT\ccm\policy\machine\actualconfig:CCM_SoftwareDistribution.ADV_AdvertisementID='$($RestartProgramDeployID)',PKG_PackageID='$($RestartProgramPackageID)',PRG_ProgramID='$($RestartProgramProgramID)'")
$Program.ADV_RepeatRunBehavior = 'RerunAlways'
$Program.ADV_MandatoryAssignments = 'True'
$Program.put()
([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule($Schedule)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment