Module/STIG/Convert/Functions.Report.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. #region Public Function <# .SYNOPSIS This public function calls ConvertFrom-StigXml and generates a basic report showing the results of the conversion, sorted by the type of stig setting that was evaluated. .PARAMETER Path The full path to the xccdf to convert. #> function Get-ConversionReport { [CmdletBinding()] [OutputType([System.Collections.ArrayList])] param ( [Parameter(Mandatory = $true)] [string] $Path ) # Read in the raw stig xml and get the list of types that are discovered [PSCustomObject] $global:stigSettings = ConvertFrom-StigXccdf -Path $path # Get the list of stig types or categories. This is used to sort and filter the results $ruleTypes = Get-RuleTypeList -StigSettings $global:stigSettings # Create an empty array to store the list in [System.Collections.ArrayList] $report = @() foreach ( $ruleType in $ruleTypes ) { $reportItem = New-Object PSObject $reportItem | Add-Member -MemberType NoteProperty -Name Type -Value $ruleType <# Get all of the STIG settings discoverd for the current type The @ will force PS to return an array so the count method works properly #> $values = @( $global:stigSettings | Where-Object {$_.GetType().Name -eq $ruleType} ) $reportItem | Add-Member -MemberType NoteProperty -Name Count -Value $values.Count <# Of the list of items that was just filtered above, count any that have an error The @ will force PS to return an array so the count method works properly #> $errorCount = @( $values | Where-Object 'status' -eq 'fail' ).Count $reportItem | Add-Member -MemberType NoteProperty -Name Errors -Value $errorCount <# Of the list of items that was filtered above, count all that pass the conversion The @ will force PS to return an array so the count method works properly #> $passcount = @($values | Where-Object 'conversionstatus' -eq 'pass').Count $reportItem | Add-Member -MemberType NoteProperty -Name ConversionPass -Value $passcount <# Of the list of items that was filtered above, count any that fail the conversion. The @ will force PS to return an array so the count method works properly #> $failcount = @( $values | Where-Object 'conversionstatus' -eq 'fail' ).Count $reportItem | Add-Member -MemberType NoteProperty -Name ConversionFail -Value $failcount [void] $report.Add($reportItem) } $report } #endregion #region Private Functions <# .SYNOPSIS Simply returns an alphabetical list of STIG types. This helps with additional sorting and searching. #> function Get-RuleTypeList { param ( [Parameter(Mandatory = $true)] [PSCustomObject] $StigSettings ) $StigSettings | Foreach-Object {$PSItem.GetType().ToString()} | Select-Object -Unique | Sort-Object } #endregion |