When server was rebooted

  • Comments posted to this topic are about the item When server was rebooted

  • Hello,

    I'd like to send this result by plain email. How can I do this?

    Thanks in advance

  • Thanks.

    Nice exercise/example. I see one could easily work in an excel writer an/or an emauler.

    For years I've been using Microsoft's uptime tool

    (uptime.exe from https://www.microsoft.com/en-us/download/details.aspx?id=14732)

    running from a batch file as part of my 'dailies.'

    Cheers from Denver,

    Mark

    Mark
    Just a cog in the wheel.

  • Please don't laugh at my script, i just started working on PowerShell for few months.

    #Last reboot time for all physical servers

    Clear-Host;

    $OutArray = @()

    FOREACH($svr in GC C:\ServerProdQaDev.txt)

    {

    $lastBootUpTime = Get-WmiObject Win32_OperatingSystem -ComputerName $svr | Select -ExpandProperty lastBootUpTime;

    $convertedLastBootUpTime = [System.Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)

    $emailBody = $svr + ' was rebooted on: ' +$convertedLastBootUpTime

    $outarray += $emailBody

    $emailBody = $null;

    }

    $OutArray | Out-File 'C:\LastRebootTime.txt'

    $From = "xxxxx.xxxx@gmail.com"

    $To = "yyyyy@yyyy.com"

    $Subject = "Last Reboot Time"

    $Body = "Please Check the following .txt attachment. Its not a virus, its your report for Last reboot time for your servers."

    $SMTPServer = "smtp.gmail.com"

    $SMTPPort = "587"

    $attachment = 'C:\LastRebootTime.txt'

    Send-MailMessage -From $From -to $To -Subject $Subject `

    -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Attachments $attachment `

    -Credential (Get-Credential)

  • Thanks for your help.

    I'll give it a try and will let your know

  • Hithere,

    to find out when a server is reboot I will login to this server (RDP), open a DOSprompt and type ''systeminfo |more" ..... done!

    besides this I run a script on all our SQL-servers reading the ERRORLOGs - and checking for "where lower(LogText) like '%registry startup parameters:%'" gives me a daily update if a server has been rebooted (or not)...

    Regards,

    Guus

  • Thanks for the nice little script.

  • mashrur shuvo (7/27/2015)


    Please don't laugh at my script, i just started working on PowerShell for few months. ...

    We don't (normally) laugh (sometimes blatant stupidity is criticized, which yours is not). Everyone starts somewhere, and PowerShell is not an easy system to master or even to get good fluency in. Very different beast from SQL Server.

    For me, I'd see server reboots in my logs, but if I were a sysadmin running a server farm I'd really appreciate such a script.

    Good job, and kudos for throwing it out there!

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • Hi,

    Your script works fine and this is what I wanted.

    Thanks again for your help

  • Thanks!

    Here's a way using TSQL

    SELECTLastServerStartDT= DATEADD(SECOND, -1 * (ms_ticks / 1000), GETDATE())

    , LastSQLStartDT= sqlserver_start_time

    FROMsys.dm_os_sys_info

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply