Created
September 29, 2016 18:07
-
-
Save rasimmers/3f1bf538821fb778c5fccb685b0577ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ReportHeader { | |
begin {} | |
process { | |
$computerSys = Get-WmiObject -Class Win32_ComputerSystem -Property Domain, Manufacturer, Model, Name | |
$rptHeader = @{ | |
ComputerName=$computerSys.Name | |
ComputerDomain=$computerSys.Domain | |
Manufacturer= $computerSys.Manufacturer | |
Model = $computerSys.Model | |
} | |
$header = New-Object -TypeName PSObject -Property $rptHeader | |
} | |
end {$header} | |
} | |
function Get-HardwareReport { | |
begin{ | |
function Test-Administrator { | |
$user = [Security.Principal.WindowsIdentity]::GetCurrent() | |
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
} | |
} | |
process { | |
$computerSys = Get-WmiObject -Class Win32_ComputerSystem -Property TotalPhysicalMemory | |
$sysHDD = Get-WmiObject -Class Win32_LogicalDisk -Filter "Name = '$env:SYSTEMDRIVE'" | |
$desktopMon = Get-WmiObject -Class Win32_DesktopMonitor -Filter "ScreenHeight IS NOT NULL" -Property ScreenWidth,ScreenHeight | |
$tests = @() | |
#Administrator Test | |
$tests += New-Object -TypeName PSObject -Property @{ | |
Name = "Administrator" | |
Description = "Report is being run in context of Administrator to gather information" | |
Criteria = "User is in Administrative Role" | |
Result = Test-Administrator -eq $True | |
ResultValue = Test-Administrator | |
Order = 1 | |
} | |
#Memory Test | |
$tests += New-Object -TypeName PSObject -Property @{ | |
Name = "Memory" | |
Description = "Systems need to have more than 8 gb of memort because of blah" | |
Criteria = "Memory (MB) is greater than or equal to 8097.5" | |
Result = ($computerSystem.TotalPhysicalMemory/1MB) -ge 8097.5 | |
ResultValue = $computerSystem.TotalPhysicalMemory/1MB | |
Order = 2 | |
} | |
#HardDrive Test | |
$tests += New-Object -TypeName PSObject -Property @{ | |
Name = "HardDrive Freespace" | |
Description = "The harddrive freespace should be greater that 500mb because of blah" | |
Criteria = "HDD (MB) is greater than or equal to 500.00" | |
Result = ($sysHDD.Freespace/1MB) -ge 500.00 | |
ResultValue = $sysHDD.Freespace/1MB | |
Order = 3 | |
} | |
#Monitor Height | |
$tests += New-Object -TypeName PSObject -Property @{ | |
Name = "Monitor Screen Height" | |
Description = "Monitor Screen Height must be less than or equal because of blah" | |
Criteria = "Monitor Screen Height is less than or equal to 1040" | |
Result = $desktopMon.ScreenHeight -le 1040 | |
ResultValue = $desktopMon.ScreenHeight | |
Order = 4 | |
} | |
#Monitor Width | |
$tests += New-Object -TypeName PSObject -Property @{ | |
Name = "Monitor Screen Width" | |
Description = "Monitor Screen Height must be less than or equal because of blah" | |
Criteria = "Monitor Screen Height is less than or equal to 1980" | |
Result = ($desktopMon.ScreenWidth -le 1980) | |
ResultValue = $desktopMon.ScreenWidth | |
Order = 5 | |
} | |
} | |
end{$tests} | |
} | |
$header = Get-ReportHeader | |
$hardware = Get-HardwareReport | |
$summary = $hardware | Group-Object Result -NoElement | Select Count, @{Name="Result";Expression={if ($_.Name -eq $true){"Success"}else{"Fail"} }} | |
$html = @" | |
<html> | |
<head> | |
<title>Report</title> | |
</head> | |
<body> | |
<h1>Computer Report: $($header.ComputerName)</h1> | |
$($header | ConvertTo-HTML -As List) | |
<h2>Hardware Test:</h2> | |
<p>These are the hardware tests for blah blah</p> | |
<h3>Hardware Summary</h3> | |
$($summary | ConvertTo-HTML -As Table) | |
<h3>Hardware Details</h3> | |
$($hardware | ConvertTo-HTML -As Table) | |
</body> | |
</html> | |
"@ | |
$path = "{0}\test.html" -f [Environment]::GetFolderPath("Desktop") | |
$html | Out-File $path | |
ii $path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment