StackOver flow has some PowerShell suggestions: https://stackoverflow.com/questions/47867949/how-can-i-check-for-a-pending-reboot#:~:text=Pending%20reboot%20can%20be%20caused%20by%20variety%20of,Install%20Install-Module%20-Name%20PendingReboot%20%23%20Run%20Test-PendingReboot%20-Detailed
From the command line, how can I tell if a reboot is pending?
Todd Chester
706
Reputation points
Hi All,
From the command line, how can I tell if a reboot is pending or delayed?
Many thanks,
-T
Windows for business | Windows Client for IT Pros | Devices and deployment | Configure application groups
3,085 questions
Windows for business | Windows Server | User experience | Other
20,213 questions
Windows for business | Windows Client for IT Pros | User experience | Other
Accepted answer
-
Sean Liming 4,766 Reputation points Volunteer Moderator
2021-12-27T18:01:49.127+00:00
1 additional answer
Sort by: Most helpful
-
Museum Systeembeheer | Liemers Kunstwerk 0 Reputation points
2024-10-12T12:40:05.75+00:00 I made a utility that might be helpfull
// // RestartOrShutdown.cs, Aad Slingerland, oktober 2024. // install-package System.Diagnostics.EventLog // See also: // https://morgantechspace.com/2013/08/convert-datetime-to-ticks-and-ticks-to.html // Limitations: // English locale only, but the texts "restart" and "power off" can be changed to another locale. // using System.Diagnostics; namespace RestartOrShutdown; internal class Program { static int Main(string[] args) { int rc = 0; int minutes = 1; try { if (args.Length > 0) { minutes = int.Parse(args[0]); } #pragma warning disable CA1416 // Validate platform compatibility EventLog syslog = new("System"); // DateTime _now = DateTime.Now; long minus = 10000000; // one second in ticks DateTime _past = _now.AddTicks(-(minus * 60 * minutes)); // Debug.WriteLine(_now.Ticks); Debug.WriteLine(_past.Ticks); // var entries = syslog.Entries.Cast<EventLogEntry>() .Where(x => x.TimeWritten.Ticks > _past.Ticks && x.EventID == 1074) .ToList(); #pragma warning restore CA1416 // Validate platform compatibility // foreach (EventLogEntry e in entries) { Debug.WriteLine(e.TimeWritten.Ticks); Debug.WriteLine(e.Message); if (e.Message.Contains("restart")) { rc = 1; } else if (e.Message.Contains("power off")) { rc = 2; } } } catch (System.FormatException) { Usage(); rc = 9; } Console.WriteLine($"Returncode={rc}"); return rc; } static void Usage() { Console.WriteLine(@" Usage: RestartOrShutdown [minutes] Queries the Operating System wether it is in the process of Restart or Shutdown. Return code 0 = neither. Return code 1 = Restarting in progress. Return code 2 = Shutdown in progress. Return code 9 = invalid argument value. The argument [minutes] defaults to 1 minute. The argument [minutes] tells this program how far to look back in the Windows System Event log for a record with EventID 1074."); } }