STIGLib.psm1
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 93 94 95 96 97 98 99 100 101 102 |
Write-Verbose 'Importing from [C:\MyProjects\STIGLib\STIGLib\private]' Write-Verbose 'Importing from [C:\MyProjects\STIGLib\STIGLib\public]' # .\STIGLib\public\Get-StigFile.ps1 function Get-StigFile { <# .SYNOPSIS Pulls list of STIG benchmarks .DESCRIPTION Get list of STIG benchmark files from https://public.cyber.mil/stigs/downloads/ .EXAMPLE Get-StigFile .NOTES Date doesn't work. #> [CmdletBinding()] param ( ) begin { $StigLibrary = Invoke-WebRequest -Uri 'https://public.cyber.mil/stigs/downloads/' -UseBasicParsing } process { foreach ($Stig in $StigLibrary.links) { if ($Stig.href -like "*/zip/*") { [string]$Name = (($Stig.outerHTML) | ForEach-Object { [regex]::matches( $_ , '(?<=</span>\s+)(.*?)(?=\s+</a>)' ) } | Select-Object -ExpandProperty value).trim() [int]$Version = (($Name) | ForEach-Object { [regex]::matches( $_ , '(?<=Ver\s+)(\d+)' ) } | Select-Object -ExpandProperty value) [int]$Release = (($Name) | ForEach-Object { [regex]::matches( $_ , '(?<=,\s+Rel\s+)(\d+)' ) } | Select-Object -ExpandProperty value) #.trim() [string]$Date = $null#(($Stig.outerHTML) | ForEach-Object { [regex]::matches( $_ , '(?<=<td class="updated_column">\s+)(.*?)(?=\s+</span>)' ) } | Select-Object -ExpandProperty value) #-replace "<span style=""display:none;"">","" [PSCustomObject]@{ Name = $Name -replace '[^ -x7e]', '' URI = $Stig.href Version = $Version Release = $Release Date = $Date } } } } end { } } # .\STIGLib\public\Save-StigFile.ps1 function Save-StigFile { <# .SYNOPSIS Saves STIG benchmark files .DESCRIPTION Saves STIG benchmark files. Accepts pipeline input .PARAMETER URI URI to file. Accepts pipeline input .PARAMETER Path Path to save file .EXAMPLE Get-StigFile | Save-StigFile -Path ".\" .NOTES General notes #> [CmdletBinding()] param ( # Parameter help description [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string[]] $URI, # Parameter help description [Parameter(Mandatory)] [String] $Path ) begin { } process { foreach ($Resource in $URI) { $FileName = ($Resource -split "/")[-1] Invoke-WebRequest -Uri $Resource -OutFile $Path\$FileName } } end { } } Write-Verbose 'Importing from [C:\MyProjects\STIGLib\STIGLib\classes]' |