Run-SystemsReport.ps1

<#PSScriptInfo
 
.VERSION 1.0.0.5
 
.GUID 17b1a674-c1bb-44e0-b113-630397db8e11
 
.AUTHOR matt.quickenden
 
.COMPANYNAME ACE
 
.COPYRIGHT
 
.TAGS Report HTML
 
.LICENSEURI
 
.PROJECTURI http://www.azurefieldnotes.com/2016/08/04/powershellhtmlreportingpart1/
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES ReportHTML
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 A computer system report, this was generated from https://www.simple-talk.com/sysadmin/powershell/building-a-daily-systems-report-email-with-powershell/ using the ReportHTML module details here. http://www.azurefieldnotes.com/2016/08/04/powershellhtmlreportingpart1/
 
#>
 
param (
    $ReportOutputPath ,
    $ReportName = "Systems Report",
    $thresholdspace = 20,
    [int]$EventNum = 5,
    [int]$ProccessNumToFetch = 10,
    #$users = "youremail@yourcompany.com", # List of users to email your report to (separate by comma)
    #$fromemail = "youremail@yourcompany.com",
    #$server = "yourmailserver.yourcompany.com", #enter your own SMTP server DNS name / IP address here
    $list = $args[0] #This accepts the argument you add to your scheduled task for the list of servers. i.e. list.txt
)

Function Import-ReportHTML {
Param (
    [Version]$version
)
    try {Import-Module ReportHtml}
    catch {Write-error "Install ReportHTML module. Install-module -name ReportHTML. Details here http://www.azurefieldnotes.com/2016/08/04/powershellhtmlreportingpart1/"}
    finally {
        $RMV= (get-module | ? {$_.name -eq 'ReportHTML'}).version 
        if ($RMV -ge $version) {
            Write-Output "ReportHTML module Version $RMV found"
        } else {
            write-output "Pretty please update the ReportHTML module. Update-module -name ReportHTML"
        }
    }
}
#endregion
Import-ReportHTML -version 1.3.0.0

#Region Logos
#convert required image to Base64 and put strings here
$Logo1 = "https://azurefieldnotesblog.blob.core.windows.net/wp-content/2016/12/ReportHTMLIcon.jpg"
$logo2 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAlgCWAAD/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OB2nGLpf5mPsW+5JuSX4TCHVLUGlt9JCzsB++E7/dWd6VLSdyk2rHhtENLI2iWk+MYNDnvXONY4aYbct9CULdAJO5SnsPP0rGnGHwfWri/xqwWe65FNx5u0THJiHIUdt0uFTfRsQsjb+ypCUrat/OoyndseW0twRnS/TbFsPjy3J0ew2uNbG5TyQlbqWW0thagOwJCd9hWKuKPgn044r7ewrKIb9uyCI2W4l/tZS3LbR3Phq3BS43ud+lQO256Snc1n6lKt9zUFu2Ky4fJpnW9b1vi663mLjjpJVAYtikFW/n1ASOg/wDtqW/CLweY1wg4zebZYLzdb4/eX25E2TcvDAK0JUlPhpQkdI2UfMqP31n2lbLRkSRU4tuAWycWWdY7k1zyy5WB6zQ/obbEOK06lweKXOolZ3B3O39lSoZb8FpCAdwkAbn7hW+lYslCNebk2rQlxJSoBSSNiCNwagjrtyitNNT8mlZDiF5nac3GSsuuxYDCJEHxD36m2iUqa3PolfT7JFTwpWRnJslbFt5NbF5djHOdaciyRlo92Y8QNkJ9kqedd6fT0NTsumSYdw76ZWv84L8xYsZs0eNbG7hdXQkAJSG2wtQAHUekeg7+1e7rxGsOjWJ68YTIxLNbaq62F91p9yMiQ4wSttXUg9TagrsfvrW3EIyFMsq61O1LxbVjmv6WX3D79CyKzl+1sCbAc62/ET4nUnf3G4/9at6R9UVGzAeXToLpjmdnyrHcOeg3y0yEyoclV2luBtxPkelThSf0EbVJQDYbVlKVNOyuPqG26trgvQ1pSlaBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoBSlKAUpSgFKUoD/9k="
#endregion
if (!$ReportOutputPath)  {$ReportOutputPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent} 

try {$computers = @(get-content $list) | sort  } #grab the names of the servers/computers to check from the list.txt file.
catch {
    if ($computers.count -eq 0) {
        Write-Warning "List empty selecting localhost $env:computername"
        $Computers = @($env:computername,$env:computername,$env:computername)
    }
}
finally {Write-output ([string]$computers.count + " computer found") }

Function Get-HostUptime {
    param ([string]$ComputerName)
    $Uptime = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName
    $LastBootUpTime = $Uptime.ConvertToDateTime($Uptime.LastBootUpTime)
    $Time = (Get-Date) - $LastBootUpTime
    Return '{0:00} Days, {1:00} Hours, {2:00} Minutes, {3:00} Seconds' -f $Time.Days, $Time.Hours, $Time.Minutes, $Time.Seconds
}

$Report = @()
$ReportBody = @()
$Disks = @()
$SystemErrors = @()
$AppErrors = @()

$Report += Get-HtmlOpenPage  -TitleText ($ReportName) -LeftLogoString $logo2 -RightLogoString $Logo1

foreach ($computer in $computers){
    $ReportBody += Get-HtmlContentOpen -IsHidden -HeaderText "System Report For - $computer"     -BackgroundShade 2
    
    #Region System & Disk
    $DiskInfo= Get-WMIObject -ComputerName $computer Win32_LogicalDisk | Where-Object{$_.DriveType -eq 3} | Select-Object SystemName, DriveType, VolumeName, Name, @{n='Size (GB)';e={"{0:n2}" -f ($_.size/1gb)}}, @{n='FreeSpace (GB)';e={"{0:n2}" -f ($_.freespace/1gb)}}, @{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} #| ConvertTo-HTML -fragment
    $Disks += $DiskInfo
    $SystemInfo = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer | Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory)
    $TotalRAM = ($SystemInfo.TotalVisibleMemorySize/1MB)
    $FreeRAM =($SystemInfo.FreePhysicalMemory/1MB)
    $UsedRAM =($TotalRAM - $FreeRAM)
    $RAMPercentFree = ($FreeRAM / $TotalRAM) * 100
    
    $ReportBody += Get-HtmlContentOpen -HeaderText "System Information" -BackgroundShade 1
        $ReportBody += Get-HTMLColumn1of2
            $ReportBody += Get-HtmlContentOpen -HeaderText "OS Information"
                $ReportBody += Get-HtmlContentText -Heading "OS" -Detail (Get-WmiObject Win32_OperatingSystem -computername $computer).caption
                $ReportBody += Get-HtmlContentText -Heading "Uptime" -Detail (Get-HostUptime -ComputerName $computer)
                $ReportBody += Get-HtmlContentText -Heading "Total RAM" -detail ([Math]::Round($TotalRAM, 2))
                $ReportBody += Get-HtmlContentText -Heading "Free RAM" -detail ([Math]::Round($FreeRAM, 2))
                $ReportBody += Get-HtmlContentText -Heading "Used RAM" -Detail ( [Math]::Round($UsedRAM, 2))
                $ReportBody += Get-HtmlContentText -Heading "RAM Free %" -Detail ( [Math]::Round($RAMPercentFree, 2))
            $ReportBody += Get-HtmlContentClose
            
            $ReportBody += Get-HtmlContentOpen -HeaderText "Disk Information"
                $ReportBody += Get-HtmlContentTable $DiskInfo
            $ReportBody += Get-HtmlContentClose
        $ReportBody += Get-HTMLColumnClose
        
        $ReportBody += Get-HTMLColumn2of2
            $PieChartObject = Get-HTMLPieChartObject      
            $PieChartObject.Title = "Disk Space"
            $PieChartObject.Size.Width = 300
            $PieChartObject.Size.Height = 300
            $DiskSpace = @();$DiskSpaceRecord = '' | select Name, Count
            $DiskSpaceRecord.Count = $DiskInfo.'FreeSpace (GB)';$DiskSpaceRecord.Name = "Free (GB)"
            $DiskSpace += $DiskSpaceRecord;$DiskSpaceRecord = '' | select Name, Count
            $DiskSpaceRecord.Count = $DiskInfo.'Size (GB)' -  $DiskInfo.'FreeSpace (GB)';$DiskSpaceRecord.Name = "Used (GB)"
            $DiskSpace += $DiskSpaceRecord
            $ReportBody += Get-HTMLPieChart -ChartObject $PieChartObject -DataSet ($DiskSpace)
        $ReportBody += Get-HTMLColumnClose
    $ReportBody += Get-HtmlContentClose
    #endregion
    
    #Region Services & Processes
    $ReportBody += Get-HtmlContentOpen -HeaderText "Processes & Services" -IsHidden
        $ReportBody += Get-HTMLColumn1of2
            $TopProcesses = Get-Process -ComputerName $computer | Sort WS -Descending | Select ProcessName, Id, WS -First $ProccessNumToFetch #| ConvertTo-Html -Fragment
            $ReportBody +=  Get-HtmlContentTable $TopProcesses
        $ReportBody += Get-HtmlColumnClose
        
        $ServicesReport = @()
        $Services = Get-WmiObject -Class Win32_Service -ComputerName $computer | Where {($_.StartMode -eq "Auto") -and ($_.State -eq "Stopped")}
        foreach ($Service in $Services) {
            $row = New-Object -Type PSObject -Property @{
                   Name = $Service.Name
                Status = $Service.State
                StartMode = $Service.StartMode
            }
        $ServicesReport += $row
        }
        $ReportBody += Get-HTMLColumn2of2
            $ReportBody += Get-HtmlContentTable $ServicesReport
        $ReportBody += Get-HtmlColumnClose
       $ReportBody += Get-HtmlContentclose
    #endregion
        
    #region Event Logs Report
        
    $Appevents = Get-EventLog -ComputerName $computer -LogName Application -EntryType Error   | group  Source | sort count -Descending | select -First 5
    $AppErrors += $Appevents
    $Sysevents = Get-EventLog -ComputerName $computer -LogName System -EntryType Error   | group  Source | sort count -Descending | select -First 5
    $SystemErrors += $Sysevents

    $ReportBody += Get-HtmlContentOpen -HeaderText "Event Logs" 
        $ReportBody += Get-HtmlContentOpen -HeaderText "Top 5 Sources of Errors" 
        $ReportBody +=  Get-HTMLColumn1of2
            $PieChartObject = Get-HTMLPieChartObject      
            $PieChartObject.Title = "System Log Top 5 Errors"
            $PieChartObject.Size.Width = 400
            $PieChartObject.Size.Height = 400
            $ReportBody += Get-HTMLPieChart -ChartObject $PieChartObject -DataSet ($Appevents)
            $ReportBody += Get-HtmlContentTable (Set-TableRowColor ( $Appevents | select name, count) -alternating  )
        $ReportBody += Get-HtmlColumnClose
        $ReportBody +=  Get-HTMLColumn1of2
            $PieChartObject = get-HTMLPieChartObject      
            $PieChartObject.Title = "Application Log 5 Errors"
            $PieChartObject.Size.Width = 400
            $PieChartObject.Size.Height = 400
            $ReportBody += Get-HTMLPieChart -ChartObject $PieChartObject -dataset ($Sysevents)
            $ReportBody += Get-HtmlContentTable (Set-TableRowColor ($Sysevents | select name, count) -alternating  )
        $ReportBody += Get-HtmlColumnClose
        $ReportBody += Get-HtmlContentClose
            
            $SystemEventsReport = @()
            $SystemEvents = Get-EventLog -ComputerName $computer -LogName System -EntryType Error -Newest $EventNum
            foreach ($event in $SystemEvents) {
                $row = New-Object -Type PSObject -Property @{
                    TimeGenerated = $event.TimeGenerated
                    EntryType = $event.EntryType
                    Source = $event.Source
                    Message = $event.Message
                }
                $SystemEventsReport += $row
            }
            $ReportBody += Get-HtmlContentOpen -HeaderText "System Event Log" -IsHidden
                $ReportBody += Get-HtmlContentTable $SystemEventsReport 
            $ReportBody += Get-HtmlContentClose
            #$SystemEventsReport = $SystemEventsReport | ConvertTo-Html -Fragment
            
            $ApplicationEventsReport = @()
            $ApplicationEvents = Get-EventLog -ComputerName $computer -LogName Application -EntryType Error -Newest $EventNum
            foreach ($event in $ApplicationEvents) {
                $row = New-Object -Type PSObject -Property @{
                    TimeGenerated = $event.TimeGenerated
                    EntryType = $event.EntryType
                    Source = $event.Source
                    Message = $event.Message
                }
                $ApplicationEventsReport += $row
            }
            $ReportBody += Get-HtmlContentOpen -HeaderText "Application Event Log" -IsHidden
                $ReportBody += Get-HtmlContentTable $ApplicationEventsReport 
            $ReportBody += Get-HtmlContentClose
        
    #$ApplicationEventsReport = $ApplicationEventsReport | ConvertTo-Html -Fragment
    #endregion
    
    # Create the chart using our Chart Function
    #Create-PieChart -FileName ((Get-Location).Path + "\chart-$computer") $FreeRAM, $UsedRAM
    $ReportBody += Get-HtmlContentClose
    $ReportBody += Get-HtmlContentClose
}

$Report += Get-HtmlContentOpen -HeaderText "Summary Informaiton" 
$Report += Get-HtmlContentText -Heading "# computers" -Detail $computers.count
$Report += Get-HtmlContentText -Heading "Low Disk Space Computers" -Detail ($Disks | where {$_.PercentFree -lt $thresholdspace}).count
$Report += Get-HtmlContentClose

$Report += Get-HtmlContentOpen -HeaderText "Detailed Computer Reports"  -BackgroundShade 3
$Report += $ReportBody
$Report += Get-HtmlContentClose
$Report += Get-HtmlClosePage
  
Save-HTMLReport -ReportName SystemsReport -ReportContent $Report -showreport


## Assemble the final report from all our HTML sections