Fixed Get-StigList technology filter

This commit is contained in:
Adam Haynes 2019-02-06 11:03:43 +01:00
Родитель ec9fddede3
Коммит 3c44a003c8
7 изменённых файлов: 56 добавлений и 30 удалений

Просмотреть файл

@ -9,29 +9,22 @@
Enforces the behavior of getting the domain name.
If a domain name is provided, it will be used.
If a domain name is not provided, the domain name of the generating system will be used.
.PARAMETER DomainName
The FQDN of the domain the configuration will be running on.
.PARAMETER ForestName
The FQDN of the forest the configuration will be running on.
.PARAMETER Format
Determines the format in which to convert the FQDN provided into and return back
.OUTPUTS
string
.EXAMPLE
Get-DomainName -DomainName "contoso.com" -Format FQDN
Returns "contoso.com"
.EXAMPLE
Get-DomainName -DomainName "contoso.com" -Format NetbiosName
Returns "contoso"
.EXAMPLE
Get-DomainName -ForestName "contoso.com" -Format DistinguishedName
@ -110,8 +103,8 @@ Function Get-DomainName
}
<#
.SYNOPSIS
returns $env:USERDNSDOMAIN to support mocking in unit tests
.SYNOPSIS
Returns $env:USERDNSDOMAIN to support mocking in unit tests
#>
Function Get-DomainFQDN
{
@ -124,8 +117,8 @@ Function Get-DomainFQDN
}
<#
.SYNOPSIS
Calls ADSI to discover the forest root (DN) and converts it to an FQDN.
.SYNOPSIS
Calls ADSI to discover the forest root (DN) and converts it to an FQDN.
#>
Function Get-ForestFQDN
{
@ -219,24 +212,57 @@ Function Get-DomainParts
}
#endregion
#region Get-StigList
<#
.SYNOPSIS
Returns an array of all available STIGs with the associated Technology, TechnologyVersion, TechnologyRole, and StigVersion.
This function is a wrapper of the StigData class, and the return of this function call will provide you with the values needed
to create a default StigData object.
Returns an array of available STIGs with the associated Technology,
TechnologyVersion, TechnologyRole, and StigVersion. This function is a
wrapper for the STIG class. The return of this function call will
provide you with the values needed to generate the STIG ruleset.
.PARAMETER Technology
The STIG technology target
.PARAMETER ListAvailable
A switch that returns all of the STIG's in the module.
.EXAMPLE
Get-StigList
Get-Stig -ListAvailable
.EXAMPLE
Get-Stig -Technology WindowsServer
#>
Function Get-StigList
Function Get-Stig
{
[CmdletBinding()]
[OutputType([PSObject[]])]
param ()
param
(
[Parameter(ParameterSetName = 'All')]
[switch]
$ListAvailable
)
return [STIG]::ListAvailable()
dynamicparam
{
$parameterName = 'Technology'
$attributes = new-object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = "__Technology"
$attributes.Mandatory = $false
$attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributeCollection.Add($attributes)
$values = [Stig]::ListAvailable($null) | Select-Object -Unique Technology -ExpandProperty Technology
$ValidateSet = new-object System.Management.Automation.ValidateSetAttribute($values)
$attributeCollection.Add($ValidateSet)
$Technology = new-object -Type System.Management.Automation.RuntimeDefinedParameter($parameterName, [string], $attributeCollection)
$paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
$paramDictionary.Add($parameterName, $Technology)
return $paramDictionary
}
process
{
<#
The ListAvailable switch is only used to prevent the $Technology
parameter from being entered, so that the List available method is
passed a null filter.
#>
return [STIG]::ListAvailable($Technology.Value)
}
}
#endregion

Просмотреть файл

@ -164,7 +164,7 @@ Class STIG
if ($propertyList.count -eq 3)
{
$null = $return.Add([STIG]::new($propertyList[0], $propertyList[1], $propertyList[2]))
$null = $return.Add([STIG]::new($propertyList[0], $propertyList[1], [version]$propertyList[2]))
}
elseif ($propertyList.Count -eq 4)
{

Просмотреть файл

@ -68,7 +68,7 @@ DscResourcesToExport = @(
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Get-DomainName',
'Get-StigList',
'Get-Stig',
'New-StigCheckList'
)

Просмотреть файл

@ -13,6 +13,6 @@ foreach ($supportFile in (Get-ChildItem -Path $pathList -File -Filter '*.ps1'))
Export-ModuleMember -Function @(
'Get-DomainName',
'Get-StigList',
'Get-Stig',
'New-StigCheckList'
)

Просмотреть файл

@ -32,12 +32,12 @@ Install-Module -Name PowerStig -Scope CurrentUser
```
Once PowerStig is installed, you can view the list of STIGs that are currently available.
The Get-StigList function queries the StigData and returns a full list.
The Get-Stig function queries the StigData and returns a full list.
This will give you an idea of what you can target in your environment.
```powershell
Import-Module PowerStig
Get-StigList
Get-Stig
```
To update a previously installed module use this command:

Просмотреть файл

@ -17,7 +17,7 @@ Describe "$moduleName module" {
Context 'Exported Commands' {
$commands = (Get-Command -Module $moduleName).Name
$exportedCommands = @('Get-DomainName', 'Get-StigList', 'New-StigCheckList')
$exportedCommands = @('Get-DomainName', 'Get-Stig', 'New-StigCheckList')
foreach ($export in $exportedCommands)
{

Просмотреть файл

@ -436,7 +436,7 @@ function Get-ValidStigVersionNumbers
$TechnologyRoleFilter
)
$versionNumbers = (Get-Stiglist |
$versionNumbers = (Get-Stig -ListAvailable |
Where-Object {$PSItem.TechnologyRole -match $TechnologyRoleFilter} |
Select-Object StigVersion -ExpandProperty StigVersion -Unique )