-
Notifications
You must be signed in to change notification settings - Fork 3
/
Set-STIGComments.ps1
47 lines (38 loc) · 1.65 KB
/
Set-STIGComments.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<####################################################################
.SYNOPSIS
Seeks STIG data, filters out the trash and exports the find
#>
$user = "ISSO"
$initpath = "c:\dwn\"
# -- This function creates the dialog box to choose the checklist file -- #
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.ShowHelp = $true
$OpenFileDialog.filter = "All files (*.ckl)| *.ckl"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-FileName
# -- Sets the $path variable to the file you chose in the dialog box -- #
$path = Get-FileName -initialDirectory $initpath
# -- Loads the contents as XML -- #
$xml = [xml](Get-Content $path)
# -- Formats date as dd/mm/YYYY and the savedate to ISO yyyyMMdd -- #
$date = Get-Date -format d
$savedate = (Get-Date).tostring("yyyyMMdd")
<#
For each $Attr (node) at the VULN level of the tree,
check the STATUS node for a match to "NotAFinding"
and then set the COMMENTS node to "Reviewed by Username on dd/mm/YYYY"
#>
ForEach ($Attr in $xml.CHECKLIST.STIGS.iSTIG.VULN) {
If ($Attr.STATUS -match "NotAFinding") {
$Attr.COMMENTS = "Reviewed by $user on $date"
}
}
# -- Save the now modified xml back to the file you initially loaded -- #
$destination = Split-Path -Path $path -Parent
$filename = [io.path]::GetFileNameWithoutExtension("$path")
$xml.Save($destination + "\" + $filename + "_$savedate.ckl")