Created
January 1, 2017 21:07
-
-
Save entelechyIT/2714c128d2497a203de8ec45fba3a33f to your computer and use it in GitHub Desktop.
Looping through XCCDF XML with PowerShell
This file contains hidden or 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
## set the path to the xml xccdf file. | |
$BenchMarkFilePath = '~\Documents\U_Windows_2012_and_2012_R2_MS_STIG_V2R6_Manual-xccdf.xml' | |
## load the content as XML | |
[xml]$Stigx = Get-Content -Path $BenchMarkFilePath -EA Stop | |
# start by parsing the xccdf security benchmark | |
if($Stigx){ | |
$StigCollection = @() | |
# loop through the xccdf benchmark collecting data into an object collection | |
foreach ($rule in $StigX.Benchmark.Group.Rule){ | |
# create a new PSObject collecting and stripping out as required. | |
$STIG = New-Object -TypeName PSObject -Property ([ordered]@{ | |
RuleID = $rule. id | |
RuleTitle = $rule.title | |
Severity = $rule.severity | |
VulnerabilityDetails = $($($($rule.description) -split '</VulnDiscussion>')[0] -replace '<VulnDiscussion>', '') | |
Check = $rule.check.'check-content' | |
Fix = $rule.fixtext.'#text' | |
ControlIdentifier = $rule.ident.'#text' | |
Control = $null # control is null as it will be added from the CCI List | |
}) | |
$StigCollection += $STIG | |
}# close foreach | |
}# close if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment