Skip to content

Instantly share code, notes, and snippets.

@Chirishman
Last active December 19, 2017 14:24
Show Gist options
  • Save Chirishman/0b2dd9599f8d90aa97881d6cb89548fb to your computer and use it in GitHub Desktop.
Save Chirishman/0b2dd9599f8d90aa97881d6cb89548fb to your computer and use it in GitHub Desktop.
Example rewrite of Ralyks' Report
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing</Title>
<style type="text/css">
* {
margin: 0;
}
html {
height: 100%;
background: #E0E0E0;
}
.wrapper {
min-height: 100%;
height: auto;
height: 99%;
margin: 0 auto -3em;
}
table#BasicInfo {
width: 90%;
margin-left: 5%;
margin-right: 5%;
padding-top: 50px;
}
th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 3px;
}
table#Controls {
width: 90%;
margin-left: 5%;
margin-right: 5%;
padding-top: 50px;
}
body {
text-align:center;
}
h1#Header {
padding-top: 50px;
}
.pass {
background-color: #008000;
}
.fail {
background-color: #FF0000;
}
</style>
</head><body>
<table>
<colgroup><col/><col/><col/><col/><col/></colgroup>
<tr><th>Computer Name</th><th>Organization</th><th>IP Address</th><th>MAC Address</th><th>Current User</th></tr>
<tr><td>FakeName</td><td>WORKGROUP</td><td>192.168.1.1</td><td>00-00-00-00-00-00</td><td>Chirishman</td></tr>
</table>
<table>
<colgroup><col/><col/><col/></colgroup>
<tr><th>Control</th><th>What was Tested</th><th>Result</th></tr>
<tr><td>AC-2(1)</td><td>Accounts are Centrally Managed</td><td>PASS</td></tr>
<tr><td>AC-7.a</td><td>Account Lockout Threshold</td><td>PASS</td></tr>
<tr><td>AC-7.a</td><td>Account Lockout Duration</td><td>FAIL</td></tr>
<tr><td>AC-8</td><td>Most Current Banner</td><td>FAIL - Unapproved or no Banner in Place</td></tr>
</table>
</body></html>
#Set your company domain here. Replace $null with 'MyCompany.com' etc.
$YourCompanyDomain = $null
#Initializes the Basic Info Table
$BasicInfoTable = @(
@{N='Computer Name';E={$env:COMPUTERNAME}},
@{N='Organization';E={(Get-WmiObject Win32_ComputerSystem).Domain}},
@{N='IP Address';E={Get-NetIPAddress | ?{ $_.AddressFamily -eq 'IPv4' -and $_.InterfaceAlias -notmatch 'Loopback' } | select -ExpandProperty IPAddress}}
@{N='MAC Address';E={Get-NetAdapter | Select -ExpandProperty MacAddress}},
@{N='Current User';E={$env:USERNAME}}
)
#Initializes the Controls Table Format
$ControlsTable = @(
@{N='Control';E={$_[0]}},
@{N='What was Tested';E={$_[1]}},
@{N='Result';E={$_[2]}}
)
#Set up a lookup so boolean True/False can be translated into 'PASS' or 'FAIL'
$BooleanLookup = @{
$true = 'PASS'
$false = 'FAIL'
}
$BannerLookup = @{
$true = ' - Using Old Banner'
$false = ' - Unapproved or no Banner in Place'
}
#Query domain account info, parse as a hashtable
$AccountInfo = (net accounts /Domain) -replace ':(\s+)','=' | select -SkipLast 2 | ConvertFrom-StringData
#Poll Registry for Legal Notice Text
$Notice = Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" | Select -ExpandProperty LegalNoticeText
#Populates the Basic Info Table
$BasicInfo = $true | select $BasicInfoTable
#Populates the Controls Table
$Controls = @(
@('AC-2(1)','Accounts are Centrally Managed',$BooleanLookup[($env:USERDNSDOMAIN -eq $YourCompanyDomain)]),
@('AC-7.a','Account Lockout Threshold',$BooleanLookup[(($AccountInfo | %{$_['Lockout threshold']} | ?{$_}) -le 5)]), #I have used Net Accounts because the other way depends upon the Active Directory module being installed
@('AC-7.a','Account Lockout Duration',$BooleanLookup[(($AccountInfo | %{$_['Lockout duration']} | ?{$_}) -ge 15)]),
@('AC-8','Most Current Banner',(($BooleanLookup[($Notice -match 'required')],$BannerLookup[($Notice -match 'may')]) -join $null))
) | Select $ControlsTable
#Display the result tables
$BasicInfo | ft
$Controls | ft
#Your custom header
$Header = "<title>Testing</Title>`r`n<style type=""text/css"">`r`n* {`r`n margin: 0;`r`n}`r`nhtml {`r`n height: 100%;`r`n background: #E0E0E0;`r`n}`r`n.wrapper {`r`n min-height: 100%;`r`n height: auto;`r`n height: 99%;`r`n margin: 0 auto -3em;`r`n}`r`ntable#BasicInfo {`r`n width: 90%;`r`n margin-left: 5%;`r`n margin-right: 5%;`r`n padding-top: 50px;`r`n}`r`nth, td {`r`n border: 1px solid black;`r`n border-collapse: collapse;`r`n padding: 3px;`r`n}`r`ntable#Controls {`r`n width: 90%;`r`n margin-left: 5%;`r`n margin-right: 5%;`r`n padding-top: 50px;`r`n}`r`nbody {`r`n text-align:center;`r`n}`r`nh1#Header {`r`n padding-top: 50px;`r`n}`r`n.pass {`r`n background-color: #008000;`r`n}`r`n.fail {`r`n background-color: #FF0000;`r`n}`r`n</style>"
$BasicInfo | ConvertTo-Html -Head $Header -PostContent (
$Controls | ConvertTo-Html -Fragment
) | Out-File -FilePath "$env:TEMP\RalyksReport.htm"
& "$env:TEMP\RalyksReport.htm"
@Chirishman
Copy link
Author

Converted the header definition to a oneliner for easier reading of the rest of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment