Freigeben über


Powershell Script to get the last SQL Server restart Time

I wrote this powershell script to find out the last SQL Server Restart times from a batch of servers in an excel sheet and output the results in an excel. The script also takes care of unreachable servers and prints a message that it could not be connected.

Although this is a simple script, the idea behind this can extended further to fetch similar information from SQL Server as required.

Usage -

The script picks up the list of servers from an excel sheet and outputs the results on the console along with an excel sheet. Progress messages are also displayed.

The script takes the below 4 parameters as described below

Parameter Defaults Description
-InputFilePath Mandatory, No defaults Provide the complete path on the drive of the excel sheet. Prerequisite for the input file is to have the first row of the excel as the column header.
-Sheet Default = ‘Sheet1’ Provide the name of the sheet where the server details are located. If not specified, the default value "Sheet1" will be considered.
-Columnnumber Default=1 Provide the column number in the excel sheet where the server names are specified.
-OutputFilePath Mandatory, No defaults Provide the folder path where the output CSV file needs to be saved. Hardcoded filename will be outputServerDetails.csv.

 

Sample output

 

Also thanks to my colleague Sourabh Agarwal (b|t) - Microsoft Premier Field engineer for helping me with ideas while building this script.

The script is attached to this blog post. Please do share your comments/views/ideas on this script.

LastRestartTime_SQLServer

Comments

  • Anonymous
    February 25, 2016
    Great post.. Please zip file here is empty :(

    • Anonymous
      July 16, 2016
      This has been fixed.