Last Boot up Time AND SP install time


I wanted to know the last bootup time and the last time a service pack installed AND I wanted the output as a HTML file.

Here are the codes for the colors that I used:
Red = #FF0000
Green = #00FF00
Blue = #0000FF
Cyan (blue and green) = #00FFFF
Magenta (red and blue) = #FF00FF
Yellow (red and green) = #FFFF00

###### Start Posh Script ########
clear 
$pingResults =('C:ScriptsPingResultspingResults.HTM') 
$RunDate  = (get-date).tostring("MM_dd_yyyy") 
$PingTime = (Get-Date -format 'hh:mm') 

#Write the preamble of the report 
Set-Content -Path $pingResults ('<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/REC-html40/strict.dtd">http://www.w3.org/TR/REC-html40/strict.dtd>') #<---- all one line
Add-Content -Path $pingResults ("<HTML> <p>") 
Add-Content -Path $pingResults ("<head> <p>") 
Add-Content -Path $pingResults ("<title> Ping Results </title>") 
Add-Content -Path $pingResults ("</head>") 
Add-Content -Path $pingResults ("<h3>Report Generated " + $RunDate + " @ " + $PingTime + "</h3> <p>") 

$PingMachines = Gc "C:\MachineList.txt" 
ForEach($MachineName In $PingMachines) 
{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" | 
Select-Object StatusCode 
If ($PingStatus.StatusCode -eq 0) { 
   $wmi = gwmi -Class Win32_OperatingSystem -EA silentlycontinue -ComputerName $MachineName 
   $lastBootTime = $wmi.ConvertToDateTime($wmi.LastBootUpTime) 
   $t1 = Get-WmiObject -Class Win32_QuickFixEngineering -EA silentlycontinue -ComputerName $MachineName | 
   Sort InstalledOn -Descending | 
   Select InstalledOn -First 1 

Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #00FF00>" + $MachineName + "</FONT></h3> Last Boot Time: " + $lastBootTime + " Latest installed update: " + $t1 + "</pre>")  <font color="#ff0000"></font> #<---- all one line
$lastBootTime = " " } 

Else { 
Add-Content -Path $pingResults ("<pre><h3>Server Name: <FONT color = #FF0000>" + $MachineName + "</FONT></h3></pre>")}  <font color="#ff0000"></font> #<---- all one line
     } 

############# End POSH Script ###############
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s