Thursday, May 24, 2018

Server UPTime Report



Get-ExchangeServer|%{
    if(Test-Connection $_.name -Count 1 -Quiet) {
        $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_.name         

        $uptime = (Get-Date) - $OS.ConvertToDateTime($OS.LastBootUpTime)           

        $report += "$($_.name) has been up for {0} days, {1} hours and {2} minutes." `
        -f $uptime.Days, $uptime.Hours, $uptime.Minutes + "`r"
    }
}

Send-MailMessage -To rakesh.chaturvedi@domain.com -From ExchangeServerReport@domain.com -Subject "Exchange Server Uptime" -Body $report -SmtpServer "SMTP-Server.domain.com"

No comments:

Post a Comment