Skip to content

Test DscProperty

dscbot edited this page Feb 13, 2024 · 2 revisions

Test-DscProperty

SYNOPSIS

Tests whether the class-based resource has the specified property.

SYNTAX

Test-DscProperty [-InputObject] <PSObject> [-Name] <String> [-HasValue] [[-Attribute] <String[]>]
 [<CommonParameters>]

DESCRIPTION

Tests whether the class-based resource has the specified property, and can optionally tests if the property has a certain attribute or whether it is assigned a non-null value.

EXAMPLES

EXAMPLE 1

Test-DscProperty -InputObject $this -Name 'MyDscProperty'

Returns $true or $false whether the property exist or not.

EXAMPLE 2

$this | Test-DscProperty -Name 'MyDscProperty'

Returns $true or $false whether the property exist or not.

EXAMPLE 3

Test-DscProperty -InputObject $this -Name 'MyDscProperty' -HasValue

Returns $true if the property exist and is assigned a non-null value, if not $false is returned.

EXAMPLE 4

Test-DscProperty -InputObject $this -Name 'MyDscProperty' -Attribute 'Optional'

Returns $true if the property exist and is an optional property.

EXAMPLE 5

Test-DscProperty -InputObject $this -Name 'MyDscProperty' -Attribute 'Optional' -HasValue

Returns $true if the property exist, is an optional property, and is assigned a non-null value.

PARAMETERS

-Attribute

Specifies if the property should be evaluated to have a specific attribute. If the property exist but is not the specific attribute the command returns $false.

Type: String[]
Parameter Sets: (All)
Aliases:

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

-HasValue

Specifies if the property should be evaluated to have a non-value. If the property exist but is assigned $null the command returns $false.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

-InputObject

Specifies the object that should be tested for existens of the specified property.

Type: PSObject
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Name

Specifies the name of the property.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
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

[System.Boolean]

[System.Boolean]

NOTES

This command only works with nullable data types, if using a non-nullable type make sure to make it nullable, e.g. [Nullable[System.Int32]].

RELATED LINKS

Clone this wiki locally