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.