Powershell Exchange Server UP Time

 

Server up time

Get-ExchangeServer | where{$_.name -like'wendy*'} | %{
    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"
    }
}
$msg=$msg+$report
  Send-MailMessage -To xxxx -From xxxx `
-Subject "Server Uptime" -Body $msg -SmtpServer xxxxx

 

posted @ 2017-06-26 21:22  寻香径  阅读(157)  评论(0编辑  收藏  举报