Not so simple pass/fail in html

First things first, if I can clarify anything PLEASE ask I’ll be lurking about attempting to look busy. I’m also limited to 2.0, only need to support IE & win7-10.

Morning/Evening Everyone! The tl/dr version of what I’m trying to do is try to mimic a pass/fail system requirements test of sorts then convert to exe so the place I’m contracting for can distribute this to their clients. I DO NOT consider myself a dev but I do know JUST enough to somewhat know what I’m talking about.

That’s gotten me into trouble here cause they now think I’m a posh pro… due to the fact I’m the only one on the team who can read what’s going on that the previous guy left. I was handed the ps1 files and told “Please make it work. with 1 click.”

I’ve a total of 14 ps1 files I’ve tried converting them to function with
Function{
giant code blocks here
}
The whole thing ends up being over 2.1k lines I believe but the core of what I’m trying is shown below. I think it’s more convoluted right now than it needs to be.

Here’s what I’m attempting to test with pass/fail.

However that’s from the main aspect of it that does pass/fail there’s quite a lot well 13 other scripts and so far not been able to consolidate without enormous amounts of errors.

Full List of Test Needing Ran
SystemAttribute                                             Status                                                     
---------------                                             ------                                                     
#Local Administrator Rights                                  pass #if test fails stop output and advise
#Check Local Administrator Status
function Test-Administrator {
    $user = [Security.Principal.WindowsIdentity]::GetCurrent()
    (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

if (Test-Administrator -eq $True) {
    $status += 'pass'
    } else {
    $status += 'fail'
    Write-Warning -message "HEY! You need to run this application as an administrator to check all the pertinent conditions and systems!"
    #Code Added By BrandonB
    break 1001
}
$systemAttrs += "Local Administrator Rights"

#Microsoft Version : 6.1.7601                                pass
#OS Check, Microsoft Windows 7 up to Microsoft Windows 10
if (ConvertTo-UInt64 $computerOS.version -ge 617601) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Microsoft Version : " + $computerOS.version)


#RAM Space : 8100.12890625                                   pass
#Check RAM Size
$RAM = $computerSystem.TotalPhysicalMemory/1MB
if ($RAM -ge 8097.5) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("RAM Space : " + $RAM)

#Processor : @{name=Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz} pass
#Check Processor
$processorName = Get-WmiObject Win32_Processor -property name | Select-Object -property name 
if ((Get-WmiObject Win32_Processor).MaxClockSpeed -ge 1900) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Processor : " + $processorName)

#HDD Space : 412416.39453125                                 pass
#Check Primary HDD Space
$HDD = $computerHDD.Freespace/1MB
if ($HDD -ge 500.00) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("HDD Space : " + $HDD)

#Screen Resolution : @{ScreenWidth=1280; ScreenHeight=1024}  pass
#Check Monitor Resolution
$screenResolution = Get-WmiObject Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight
if ($screenResolution.ScreenHeight -le 1040 -and $screenResolution.ScreenWidth -le 1980) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Screen Resolution : " + $screenResolution)

#USB Ports Check :                                           pass
#Check USB Connections
$colDevices = Get-WmiObject -class Win32_USBHub | Select-Object -property Name, Status
$arrUSBVersion = @()

foreach ($objDevice in $colDevices) {
    if ($objDevice.Status -like "OK") {
        $isExists = $true
    } else {
        $isExists = $false
    }
    
}

if ($isExists -eq $true) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("USB Ports Check : " + $ver)

#Internet Explorer Version : 9.11.9600.18376                 pass
#Check IE Version
$register = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computerName)
$key = $register.OpenSubkey($keyname)
$value = $key.GetValue('Version')
if ($value -ge 9.1) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Internet Explorer Version : " + $value)

#.NET Version :                                              pass
#Check .NET Version
$version = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object {$_.DisplayName -match "Microsoft .NET Framework"}
if ($version.DisplayVersion -ge 2.0 -or $version.DisplayVersion -le 4.0) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += (".NET Version : " + $version.DisplayVersion)

#Adobe Version : 11.0.16                                     pass
#Check Adobe Version
$flashObject = Get-WmiObject -class Win32_Product | Where-Object {$_.Name -match "Adobe Reader"}
$version = $flashObject.Version
if (ConvertTo-UInt64 $version -ge 11) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Adobe Version : " + $flashObject.Version)

#SilverLight Version : 5.1.41212.0                           pass
#Check SilverLight Version
$version = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object {$_.DisplayName -eq "Microsoft Silverlight"}

if (ConvertTo-UInt64 $version.DisplayVersion -ge 51412120) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("SilverLight Version : " + $version.DisplayVersion)

Trusted Website Check: http://dpm.site1.com/wddl            fail
Trusted Website Check: http://express.site2.com             fail
Trusted Website Check: http://site3.com                     fail
#Checking Internet Trusted Websites
function CheckTrustedWebsite {
    param (
        [String] $siteName
        
    )
    
    $trustedSites = $(get-item "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMapKey").property
    foreach ($site in $trustedSites) {
        if ($site -like $siteName) {
            $boolResult = $true
        } else {
            $boolResult = $false
        }
    }   
}
    
CheckTrustedWebsite "*dpm.site1.com*"
if ($boolResult) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Trusted Website Check: http://site1.com/wddl") 

CheckTrustedWebsite "*express.site2.com*"
if ($boolResult) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Trusted Website Check: http://site2.com") 

CheckTrustedWebsite "*direct.site3.com*"
if ($boolResult) {
    $status += 'pass'
} else {
    $status += 'fail'
}
$systemAttrs += ("Trusted Website Check: http://site3.com") 


#Browser Compatibility Check                                 fail #I believev because we're locked by GPO
#Browser Compatibility Check
$HKEY_CURRENT_USER = 2147483649
$strComputer = Get-Content Env:computerName
$strKey = "Software\Microsoft\InternetExplorer\BrowserEmulation\"
$isExists = $false
$strVersion = ""

$objReg = New-Object System.Management.ManagementClass "Root/default:StdRegProv"

$arrValueNames,$arrTypes = $objReg.EnumValues($HKEY_CURRENT_USER,$strKey)
foreach ($arrValue in $arrValueNames) {
    if ($arrValue -like "ALLSITECOMPATIBILITYMODE") {
        $isExists = $true
        $strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $arrValue)

    }       
}
    
if ($isExists) {
    if ([int]$strValue > 0) {
        $status += 'pass'
    } else {
        $status += 'fail'
    }
} else {
    $status += 'fail'
}
$systemAttrs += ("Browser Compatibility Check")

#Web Data Settings Check                                     fail #Still not sure what he was checking here.
#Get Web Data Settings
$HKEY_CURRENT_USER = 2147483649
$strKey = "Software\Microsoft\InternetExplorer\BrowserEmulation\"
$isExists = $false
$strVersion = ""

$objReg = [WMIClass]"root\default:StdRegProv"
$arrValueNames, $arrTypes = $objReg.EnumValues($HKEY_CURRENT_USER, $strKey)

foreach ($arrValue in $arrValueNames) {
    if ($arrValue -like "SYNCMODE5") {
        $isExists = $true
        $strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $arrValue)
    }

}

$strResult = ""
if ($isExists) {
    if ([int]$strValue = 3) {
        $status += 'pass'
    } else {
        $status += 'fail'
    }
} else {
    $status += 'fail'
}
$systemAttrs += ("Web Data Settings Check")

#ActiveX Settings Check : Enabled                            pass
#Check ActiveX Settings
$HKEY_CURRENT_USER = 2147483649
$strKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
$valueName = "1200"
$objReg = [WMIClass]"root\default:StdRegProv"

$strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $valueName) | Select-Object -property ReturnValue 
$strResult = ""

switch ($strValue.ReturnValue) {
    0 {$strResult = "Enabled"
       $status += "pass"}
    1 {$strResult = "Prompt"
       $status += "fail"}
    3 {$strResult = "Disabled"
       $status += "fail"}
    default {$strResult = "Unknown"}
}

$systemAttrs += ("ActiveX Settings Check : " + $strResult)


#ActiveX Scripting Settings Check : Prompt                   fail
#Check Script ActiveX Settings
$strKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
$valueName = "1405"
$objReg = [WMIClass]"root\default:StdRegProv"

$strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $valueName) | Select-Object -property ReturnValue 
$strResult = ""

switch ($strValue.ReturnValue) {
    0 {$strResult = "Enabled"
       $status += "pass"}
    1 {$strResult = "Prompt"
       $status += "fail"}
    3 {$strResult = "Disabled"
       $status += "fail"}
    default {$strResult = "Unknown"}
}
$systemAttrs += ("ActiveX Scripting Settings Check : " + $strResult)


#Computer Authentication Check : Enabled                     pass #Unsure of what was being checked here also.
#Check Run Comp Authentication 
$strKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
$valueName = "2004"
$objReg = [WMIClass]"root\default:StdRegProv"
$strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $valueName) | Select-Object -property ReturnValue 
$strResult = ""

switch ($strValue.ReturnValue) {
    0 {$strResult = "Enabled"
       $status += "pass"}
    1 {$strResult = "Prompt"
       $status += "fail"}
    3 {$strResult = "Disabled"
       $status += "fail"}
    default {$strResult = "Unknown"}
}
$systemAttrs += ("Computer Authentication Check : " + $strResult)



#Created a custom PS Object to output data
$objectCollection = @()

for ([int]$i = 0; $i -lt 19; $i++) {

    $currentStatus = $status[$i]
    $currentAttr = $systemAttrs[$i]
    
    $object = New-Object PSObject
    Add-Member -InputObject $object -MemberType NoteProperty -Name SystemAttribute -Value ""
    Add-Member -InputObject $object -MemberType NoteProperty -Name Status -Value ""
    
    $object.SystemAttribute = $currentAttr
    $object.Status = $currentStatus

    $objectCollection += $object
    
}

$objectCollection | Out-File "TestResults.txt" | Format-Table -Autosize
$objectCollection | clip
#[Environment]::Exit("$ExitCode"

Alternativly if you know a way to consolidate 14 scripts into a single exe (I’ve tried ps1ToExe to no avail) Also tried converting to functions, but more errors than I could figure out myself. I’ve to be cautions on code shared as I’m working with a financial institution but I’m happy to share what code I can if it helps you help me I’ll just have to go through line by line removing server info etc that has personal info or possibility thereof.

What are you doing with the results? If it fails, what is the remediation action? What are you trying to solve? It really appears that you are trying to do more of Desired State Configuration (DSC). While DSC is really built for servers, it really seems like that is what you are trying to do. Powershell does have the ability to do DSC, there is a forum thread dedicated to it.

Thanks for the response Mr. Simmers. If this is something that can be done simpler through DSC I’m MORE than happy to look into it and will venture there. In short I’m trying to test for basic system requirements through powershell (or any other method) but it was started in posh by a gent who is no longer here.

Pardon the medium as it’s only one I’ve ever had luck using regardless of industry.
Image over @ Padlet

There’s a total of 14 different files. In short I’m trying to get a ps1 file to test for local admin access, and if i’s available set a pass flag and output pass/fail to user in html format.

Check, Microsoft Windows 7 up to Microsoft Windows 10 if it falls in the range pass if not fail.

Check for Ram above 8gb if above display pass if not fail

Check for Max Clock Speed on processor greater or equal to 1900 same logic with pass/fail through the project here

Check Primary Hdd space output a pass/fail

Check for monitor resolution

Usb availability (that there ARE ports not if currently in use)

Check Browser version is Ie 8 or higher (if I recall min ver)

Check .Net vesion

Check Adobe Version is above threshold

Check Silverlight version is above threshold

check for 3 varying sites are listed in zone2 (trusted IE settings)

Check browser compatibility mode settings if set to true

Check availability to run activeX controls
ActiveX controls marked safe for scripting
.Net framework can run code not signed with Authentic code

I MAYBE able to post an output image depending on firewall settings here.

And in a nut shell want this idiot proof a simple follow the link or an exe to run/scan/output for end users outside of financial institution to see if they’re capable of running the software being sent out.

These are the steps tier 1 support are taking the most time on so trying to eliminate as much as possible.

There are a lot of examples of reporting in HTML. There is even a free e-book available Creating HTML Reports in Powershell.

Here is a basic example. Consider what you want to be in the report. What are you testing? Why are you testing? What are you expecting? What is the actual value? Another consideration is sorting the values. If you want to sort alphabetically, no worries. If you want to keep certain results together in a “custom order”, you should consider putting an index or order that you can sort by later, like a subcategory. This is one of many ways that you can modularize the code:

There is no styling in the report. I would recommend getting the data you want first, then work on making it pretty. HTML can be tricky since there are many ways it can render based on the browser someone opens it with. If you’re going to send it in email, it can be even trickier. Make sure that you know how the reports will be opened and utilized.