June 29, 2015 at 6:17 pm
Comments posted to this topic are about the item When server was rebooted
July 24, 2015 at 7:12 am
Hello,
I'd like to send this result by plain email. How can I do this?
Thanks in advance
July 24, 2015 at 8:59 am
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.
July 27, 2015 at 12:58 pm
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)
July 27, 2015 at 1:08 pm
Thanks for your help.
I'll give it a try and will let your know
July 28, 2015 at 12:54 am
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
July 28, 2015 at 7:29 am
Thanks for the nice little script.
July 28, 2015 at 10:48 am
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]
July 28, 2015 at 12:02 pm
Hi,
Your script works fine and this is what I wanted.
Thanks again for your help
August 10, 2015 at 3:03 am
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