microsoft / PowerStig

STIG Automation
https://www.powershellgallery.com/packages/PowerSTIG
Other
546 stars 113 forks source link

Add Get-STIGXccdfBenchmark Content to PowerSTIG.Document to break reliance on code from PowerSTIG.Convert #645

Closed thetalljosh closed 4 years ago

thetalljosh commented 4 years ago

Adding the following functions in to functions.checklist would allow users to utilize the PowerSTIG.Document workflow from the PSGet Install-Module, without having to pull down the entire Repo.

function Get-StigXccdfBenchmarkContent { [CmdletBinding()] [OutputType([xml])] param ( [Parameter(Mandatory = $true)] [string] $Path )

if (-not (Test-Path -Path $Path))
{
    Throw "The file $Path was not found"
}

if ($Path -like "*.zip")
{
    [xml] $xccdfXmlContent = Get-StigContentFromZip -Path $Path
}
else
{
    [xml] $xccdfXmlContent = Get-Content -Path $Path -Encoding UTF8
}

$xccdfXmlContent.Benchmark

}

<# .SYNOPSIS Extracts the xccdf file from the zip file provided from the DISA website.

.PARAMETER Path
    The literal path to the zip file.

>

function Get-StigContentFromZip { [CmdletBinding()] [OutputType([xml])] param ( [Parameter(Mandatory = $true)] [string] $Path )

# Create a unique path in the users temp directory to expand the files to.
$zipDestinationPath = "$((Split-Path -Path $Path -Leaf) -replace '.zip','').$((Get-Date).Ticks)"
Expand-Archive -LiteralPath $Path -DestinationPath $zipDestinationPath
# Get the full path to the extracted xccdf file.
$getChildItem = @{
    Path = $zipDestinationPath
    Filter = "*Manual-xccdf.xml"
    Recurse = $true
}

$xccdfPath = (Get-ChildItem @getChildItem).fullName
# Get the xccdf content before removing the content from disk.
$xccdfContent = Get-Content -Path $xccdfPath
# Cleanup to temp folder
Remove-Item $zipDestinationPath -Recurse -Force

$xccdfContent

}

erjenkin commented 4 years ago

Hello @thetalljosh,

Thanks for the issue! There was a change implemented in 4.4.0, so that PowerSTIG.Convert will be included when users utilize the PSGet Install-Module method of installing PowerSTIG. That milestone is set to release on 04JUL20.

Thanks,

Eric