Show message to logon user before reboot

Welcome Forums General PowerShell Q&A Show message to logon user before reboot

Viewing 6 reply threads
  • Author
    Posts
    • #276243
      Participant
      Topics: 15
      Replies: 20
      Points: 158
      Rank: Participant

      Hi, I need a script which check if machine is required a reboots and if the reboot is required the reboot a machine but if any user is logon it show them a message and when user click on the message it reboots the machine.

      Its showing message to any account including system

      • This topic was modified 1 month, 2 weeks ago by lalajee.
      • This topic was modified 1 month, 2 weeks ago by lalajee.
      • This topic was modified 1 month, 2 weeks ago by grokkit. Reason: code formatting - please read the guide
    • #276273
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

      Are these Windows patches? How are the patches being deployed? Patches are deployed as SYSTEM and scripts with GUI’s are executed as a USER. Provide details about exactly what you are doing and there is usually pre-built or vendor solutions to this issue as it’s a common ask.

    • #276288
      Participant
      Topics: 15
      Replies: 20
      Points: 158
      Rank: Participant

      Patches are stored locally on a machine and being applied with wusa.exe Patch /quiet /norestart /log:logfileĀ  (As system account) through a PowerShell script during a windows 10 1809 upgrade.

      We need to make sure that if any user is logon we can show them a message before forcing a reboot.

      Once the patch is applied and if no user is logged on then reboot the machine but if the user is logged on then show the message and then reboot the machine

       

    • #276291
      Participant
      Topics: 15
      Replies: 20
      Points: 158
      Rank: Participant

      I tried following but again it’s not picking up active users. I need to make sure if users are login through RDP or consol it show them a message before reboot.

      function Test-PendingReboot
      {
      if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
      if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
      if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }

      try {
      $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
      $status = $util.DetermineIfRebootPending()
      if (($status -ne $null) -and $status.RebootPending)
      {
      return $true
      }
      }
      catch { }
      return $false
      }

      if(Test-PendingReboot)
      {
      Add-Type -AssemblyName PresentationCore,PresentationFramework
      $ButtonType = [System.Windows.MessageBoxButton]::OK
      $MessageIcon = [System.Windows.MessageBoxImage]::Warning
      $MessageBody = "Please click on OK to reboot machine?"
      $MessageTitle = "Confirm Reboot"

      $activeUser = query session | where {$_ -match 'console'}
      if($activeUser)
      {
      $Result = [System.Windows.Forms.MessageBox]::Show($THIS, $MessageBody, $MessageTitle, $ButtonType, $MessageIcon)
      }

      shutdown -r -f -t 0
      }

       

    • #276303
      Participant
      Topics: 15
      Replies: 20
      Points: 158
      Rank: Participant

      Script will being running as SYSTEM but need to make sure it shows message to current active user

       

    • #276306
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

      This indicates you are manually patching machines…

      Patches are stored locally on a machine and being applied with wusa.exe Patch /quiet /norestart /log:logfile  (As system account) through a PowerShell script during a windows 10 1809 upgrade

      This indicates you have SCCM…

      $util = [wmiclass]”\\.\root\ccm\clientsdk:CCM_ClientUtilities”

      Why are the upgrades not being managed from SCCM?

    • #276312
      Participant
      Topics: 15
      Replies: 20
      Points: 158
      Rank: Participant

      When you upgrade the machine from 1809 to 1909 the search bar is not working and the patch we are applying is not approved within our Org.

      I’m using SCCM to apply the upgrade but the patch is being applied through a batch file usign wusa.exe

       

Viewing 6 reply threads
  • You must be logged in to reply to this topic.