Powershell Operator and AD commands


server up time report


$servers = "mccoyb02","foo","mccoyb01","reisrv1"
$path = "c:\ephemeral\uptime.html" 

$header = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>System Status Report</title>
<style type="text/css">
<!--
body {
background-color: #E0E0E0;
font-family: sans-serif
}
table, th, td {
background-color: white;
border-collapse:collapse;
border: 1px solid black;
padding: 5px
}
-->
</style>
"@
$body = @"
<h1>Server Status</h1>
<p>The following report was run on $(get-date).</p>
"@

$results = foreach ($server in $servers) 
{ 
    if (Test-Connection $server -Count 1 -ea 0 -Quiet) 
    { 
        $status = "Up" 
    } 
    else 
    { 
        $status = "Down"
    } 
    [PSCustomObject]@{
        ServerName = $server
        Reuslts = $status
    }
} 

$results | ConvertTo-Html -head $header -body $body | foreach {
    $PSItem -replace "<td>Down</td>", "<td style='background-color:#FF8080'>Down</td>"
} | Out-File C:\Ephemeral\uptime.html
& .\uptime.html


sample report:


%d bloggers like this: