STIGLib.psm1

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]'