Book Image

Windows Server 2012 R2 Administrator Cookbook

By : Jordan Krause
Book Image

Windows Server 2012 R2 Administrator Cookbook

By: Jordan Krause

Overview of this book

Table of Contents (17 chapters)
Windows Server 2012 R2 Administrator Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using PowerShell to view system uptime


I find myself constantly checking servers to figure out what time they last restarted. Usually, this is part of troubleshooting something in order to figure out whether the server rebooted as a planned action or if something went wrong and it restarted on its own during a non-standard time. For years, I had launched Event Viewer, waited for the System logs to open, hoped that they weren't corrupted in some way, and then headed over to noon on the previous day to find the amount of seconds that the system had been online. Then I'd pull out the calculator and do the math on how many days/hours that really was. Way too complicated! Thankfully, we can make calls into WMI objects with PowerShell, and there is an object in there that will tell us the last time the server started. With a few lines plugged into a .ps1 script, we can create ourselves a nice little tool that will output the last time that a server booted. Let's give it a try.

Getting ready

We are...