Blog Post

How Long has Your SQL Server Been Online

,

This week’s blog post will help you check your SQL Servers up-time. There are numerous reasons I can think of that you would want to know how long your SQL Server has been online. Was the server recently patched, did it crash and come back online, or did someone restart it by mistake? These are all valid questions about a single SQL Server or your entire estate. I will show you how you can easily check one too many servers quickly for uptime.

We will start by using every DBA’s favorite PowerShell module…  dbatools

Basics

For this example, I will introduce you to the Get-DbaUpTime function in the dbatools PowerShell module. This function has all the information we are attempting to gather.

Get-DbaUptime -SqlInstance DemoServer

This example displays when Windows and SQL Server were last started. These are critical pieces of information, depending on what you are troubleshooting.

For a different view of the output, we can pipe the command to

Out-Gridview.

Get-DbaUptime -SqlInstance DemoServer | Out-GridView

Now you have a graphical interface to filter records to find what you are looking for as your investigation grows.

Enhanced

What if your Infrastructure team just finished their monthly Windows Patching of all development servers? Do you know if the SQL Servers have been rebooted? Do you want to RDP each of them to see when the last reboot was? No, you sure do not?

Combining SQL Server Central Management Server and the

Get-DbaUpTime function work well together.

$servers = Get-DbaRegisteredServer -SqlInstance CMS -Group "SDLCDev"
Get-DbaUptime -SqlInstance $servers | Out-GridView

From the output, you can see that one server has been up four days less than the rest of the servers.  So if you had maintenance six days ago, that one server would stand out as something that might need investigation.

You get the idea of where you can go with this command and how it can be very beneficial to monitor your SQL Server environment.

Extra

Lastly, let me show you how to take this information to another level and save it to a report format that can be sent to a website or e-mailed to a list of managers.

I ran across this freely distributed module that allows you to send your PowerShell output to an HTML file. As part of the PSWriteHTML module, you have the Out-HtmlView, an HTML replacement for

Out-GridView.

Get-DbaUptime -SqlInstance $servers | Out-GridHtml -Title "Up Time Report" -FilePath C:TempDbaUpTime.html

Look at that beautiful HTML output. Not only do you get a clean HTML report, but it is also sortable, searchable, and exportable. Attach this to an e-mail or a service ticket, and you have your validation of SQL Server uptime.

Post it to a website, and you automatically have a web page that shows SQL Server Uptime.

 

Enjoy and see you on the next blog.

The post How Long has Your SQL Server Been Online appeared first on GarryBargsley.com.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating