Sunday, March 5, 2017

Uptime

$head = "<style>
BODY{font-family:FONT: 0.5pt/1pt Verdana; background-color:lightblue;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{font-size:1.15em; border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#CCCCFF} TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:pink}
</style>"
$header = "<H1>System Uptime Report for Citrix Server</H1>"
$title = "Example HTML Output"
$logfile = "C:\Scripts\DVCI\uptime\uptime.html"
$computerlist = "C:\Scripts\DVCI\uptime\serverlist.txt"
#param([string] $serverList)

If ($computerlist)
{
    $computers = Get-Content $computerlist
}

$Info = @{}



foreach ($computer in $computers)
{
    $wmi = Get-WmiObject -ComputerName $computer -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem"
    $now = Get-Date
    $boottime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
    $uptime = $now - $boottime
    $d =$uptime.days
    $h =$uptime.hours
    $m =$uptime.Minutes
    $s = $uptime.Seconds
    $Info.$computer = "$d Days $h Hours $m Min $s Sec"
}
 $result = ($Info.GetEnumerator() | ForEach-Object { New-Object PSObject -Property @{ Server = $_.Key; Uptime = $_.Value; Last_Reboot = $boottime } | Select-Object -Property Server, Uptime, Last_Reboot })
 $result |ConvertTo-Html -Head $head -body $header -Title $title |Out-File "C:\Scripts\DVCI\uptime\uptime.html"

No comments:

Post a Comment