PowerShell GUI Restart Prompt

When deploying software via SCCM I thought wouldn’t it be nice if there was greater flexibility regarding system reboot prompts for the end user. This script does exactly that. This can be used as part of an SCCM TS.

5 Star
3,650 times
Add to favorites
System Center
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • UI on RemoteServer error
    1 Posts | Last post October 18, 2019
    • I am using SolarWinds Patch Manager to execute this script and getting following error.
      Exception calling "ShowDialog" with "0" argument(s): "Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."
  • Change scheduling + Add Single Deferment?
    1 Posts | Last post August 16, 2019
    • Trying to modify this to where it will give them a 'Defer 1 Hour" option, or Reboot.  At the end of the hour, it pops up again and only has the reboot option.
      Been digging around the net for something like this, but this is as close as I can find.  Any ideas?
  • Is it possible to modify so it detects pending restart?
    1 Posts | Last post August 06, 2019
    • Would it be possible to add a code for the script to detect pending restart? This will immediately prompt the user that needs to schedule or reboot the computer right away.
  • Pending Reboot condition
    2 Posts | Last post July 09, 2019
    • Hello,
      Is it possible to add the condition (Pending Reboot) only if the system is not restarted from xyz days then prompt for the notification ?
    • Here's some code that would add a test for last restart and only restart if it has not been restarted in over 7 days.
      #endregion Source: MainForm.psf 
      # Get time of last restart
      $lastRestart = [System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime)
      # get current time
      $now = [DateTime]::Now
      # calculate the difference in decimal days of how long it has been since the last restart
      $daysSinceLastRestart = ($now-$lastRestart).TotalDays
      if ($daysSinceLastRestart -gt 7) {
          #Start the application 
          Main ($CommandLine)
  • Add a Delay Button
    2 Posts | Last post May 25, 2019
    • This is an awesome script!
      Changing timer countdown to minutes and removing the Cancel and close buttons are great additions, that I have implemented.
      I would like to add a Delay button that would 10 minutes to the countdown timer to increase the delay before restart.
      The quickest for most would be to convert the Cancel button to a Delay button that adds your specified amount of time.
      Thanks, Tony
    • Hey Tony, Any chance you can share this script? 
  • Timer display in minutes and seconds
    2 Posts | Last post April 19, 2019
    • This is a fantastic script!
      Is there a way to have the timer display minutes and seconds remaining?  We'd like to give the users an hour countdown displayed as minutes and seconds.
    • I have modified the script as below which will show you the timer in hh:mm:ss format. 
      	# User Generated Script
      	$TotalTime = 60 #in minutes
      	#TODO: Initialize Form Controls here
      	$labelTime.Text = "{0:D0}" -f $TotalTime #$TotalTime
      	#Add TotalTime to current time
      	$script:StartTime = (Get-Date).AddMinutes($TotalTime)
      	#Start the timer
      	# Define countdown timer
      	[TimeSpan]$span = $script:StartTime - (Get-Date)
      	#Update the display
      	$labelTime.Text = "{0:N0}:{1:N0}:{2:N0}" -f $span.Hours,$span.Minutes,$span.Seconds
      	if ($span.TotalSeconds -le 0)
              $ExitCode = 0
              Restart-Computer -Force
              Exit $ExitCode
      It will also pass the exit code 0 to SCCM. 
  • Best way to get make it undismissable
    2 Posts | Last post April 19, 2019
    • How do i gray out the "Close" busston and remove the "X" on top right ?
    • Just add the below line in the MainForm section
      $MainForm.Controlbox = $True
      This will remove the whole controlbox (minimize, maximize and close buttons)
      I don't think you can remove just the X from the Controlbox. 
      Another option would be to prevent users from closing the form. Just add the below at the end of the script
          $_.cancel = $false
      #Show the Form
          return $MainForm.ShowDialog()
  • Recommended procedure
    1 Posts | Last post November 13, 2018
    • Awesome! 
      Does this run in the user context or System context?
      Is there a recommended way of deploying this script?