Skip to content

Assert BoundParameter

dscbot edited this page Feb 13, 2024 · 2 revisions

Assert-BoundParameter

SYNOPSIS

Throws an error if there is a bound parameter that exists in both the mutually exclusive lists.

SYNTAX

MutuallyExclusiveParameters

Assert-BoundParameter -BoundParameterList <Hashtable> -MutuallyExclusiveList1 <String[]>
 -MutuallyExclusiveList2 <String[]> [<CommonParameters>]

RequiredParameter

Assert-BoundParameter -BoundParameterList <Hashtable> -RequiredParameter <String[]>
 [-IfParameterPresent <String[]>] [<CommonParameters>]

DESCRIPTION

This command asserts passed parameters. It takes a hashtable, normally $PSBoundParameters. There are two parameter sets for this command.

There is no built in logic to validate against parameters sets for DSC so this can be used instead to validate the parameters that were set in the configuration.

MutuallyExclusiveParameters

This parameter set takes two mutually exclusive lists of parameters. If any of the parameters in the first list are specified, none of the parameters in the second list can be specified.

RequiredParameter

Assert that required parameters has been specified, and throws an exception if not. Optionally it can be specified that parameters are only required if a specific parameter has been passed.

EXAMPLES

EXAMPLE 1

$assertBoundParameterParameters = @{
    BoundParameterList = $PSBoundParameters
    MutuallyExclusiveList1 = @(
        'Parameter1'
    )
    MutuallyExclusiveList2 = @(
        'Parameter2'
    )
}
Assert-BoundParameter @assertBoundParameterParameters

This example throws an exception if $PSBoundParameters contains both the parameters Parameter1 and Parameter2.

EXAMPLE 2

Assert-BoundParameter -BoundParameterList $PSBoundParameters -RequiredParameter @('PBStartPortRange', 'PBEndPortRange')

Throws an exception if either of the two parameters are not specified.

EXAMPLE 3

Assert-BoundParameter -BoundParameterList $PSBoundParameters -RequiredParameter @('Property2', 'Property3') -IfParameterPresent @('Property1')

Throws an exception if the parameter 'Property1' is specified and either of the required parameters are not.

PARAMETERS

-BoundParameterList

The parameters that should be evaluated against the mutually exclusive lists MutuallyExclusiveList1 and MutuallyExclusiveList2. This parameter is normally set to the $PSBoundParameters variable.

Type: Hashtable
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-IfParameterPresent

One or more parameter names that if specified will trigger the evaluation. If neither of the parameter names has been specified the evaluation of required parameters are not made.

Type: String[]
Parameter Sets: RequiredParameter
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-MutuallyExclusiveList1

An array of parameter names that are not allowed to be bound at the same time as those in MutuallyExclusiveList2.

Type: String[]
Parameter Sets: MutuallyExclusiveParameters
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-MutuallyExclusiveList2

An array of parameter names that are not allowed to be bound at the same time as those in MutuallyExclusiveList1.

Type: String[]
Parameter Sets: MutuallyExclusiveParameters
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RequiredParameter

One or more parameter names that is required to have been specified.

Type: String[]
Parameter Sets: RequiredParameter
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

RELATED LINKS

Clone this wiki locally