Generate HTML file with uptime of servers.
This script will generate an uptime File called uptime.html in the folder c:housekeeping
This script is orginally created by Ed Wilson of Microsoft. I adjusted it so that the date and time stamp is added to the file. This way you can see the history if you schedule is script on a regular bases. You will be able to see if reboots have occured.
# ----------------------------------------------------------------------------- # Script: HTML_UptimeReport.ps1 # Author: ed wilson, msft # Date: 08/06/2012 15:11:03 # Keywords: Scripting Techniques, Web Pages and HTAs # comments: Get-Wmiobject, New-Object, Get-Date, Convertto-HTML, Invoke-Item # HSG-8-7-2012 # # Modified : 01/24/2013 # By : Wessel van Sandwijk # Added date format # ----------------------------------------------------------------------------- Param( [string]$path = "c:\housekeepinguptime.html", [array]$servers = @("server1,Server2") ) Function Get-UpTime { Param ([string[]]$servers) Foreach ($s in $servers) { $os = Get-WmiObject -class win32_OperatingSystem -cn $s $boottime = [System.Management.ManagementDateTimeConverter]::ToDateTime($os.LastBootupTime) $timedifference = New-TimeSpan -Start $boottime $days = $timedifference.TotalDays New-Object psobject -Property @{computer=$s; uptime = '{0:0.0}' -f $days} } } # Entry Point *** Get-UpTime -servers $servers | ConvertTo-Html -As Table -body " <h1>Server Uptime Report</h1> The following report was run on $(get-date)" >> $path Invoke-Item $path
More Stories
Running PowerShell Hyper-V and VMWare Modules
Extend the Evaluation Period on Windows Server
Now using Ansible, Chocolatey, Powershell