-
Notifications
You must be signed in to change notification settings - Fork 9
Compare DscParameterState
This method is used to compare current and desired values for any DSC resource.
Compare-DscParameterState [-CurrentValues] <Object> [-DesiredValues] <Object> [[-Properties] <String[]>]
[[-ExcludeProperties] <String[]>] [-TurnOffTypeChecking] [-ReverseCheck] [-SortArrayValues]
[-IncludeInDesiredState] [-IncludeValue] [<CommonParameters>]
This function compare the parameter status of DSC resource parameters against the current values present on the system, and return a hashtable with the metadata from the comparison.
Note
The content of the function Test-DscParameterState
has been extracted and now
Test-DscParameterState
is just calling Compare-DscParameterState
.
This function can be used in a DSC resource from the Get function/method.
$currentValues = @{
String = 'This is a string'
Int = 1
Bool = $true
}
$desiredValues = @{
String = 'This is a string'
Int = 99
}
Compare-DscParameterState -CurrentValues $currentValues -DesiredValues $desiredValues
The function Compare-DscParameterState compare the value of each hashtable based on the keys present in $desiredValues hashtable. The result indicates that Int property is not in the desired state. No information about Bool property, because it is not in $desiredValues hashtable.
$currentValues = @{
String = 'This is a string'
Int = 1
Bool = $true
}
$desiredValues = @{
String = 'This is a string'
Int = 99
Bool = $false
}
$excludeProperties = @('Bool')
Compare-DscParameterState `
-CurrentValues $currentValues `
-DesiredValues $desiredValues `
-ExcludeProperties $ExcludeProperties
The function Compare-DscParameterState compare the value of each hashtable based on the keys present in $desiredValues hashtable and without those in $excludeProperties. The result indicates that Int property is not in the desired state. No information about Bool property, because it is in $excludeProperties.
$serviceParameters = @{
Name = $Name
}
$returnValue = Compare-DscParameterState `
-CurrentValues (Get-Service @serviceParameters) `
-DesiredValues $PSBoundParameters `
-Properties @(
'Name'
'Status'
'StartType'
)
This compares the values in the current state against the desires state. The command Get-Service is called using just the required parameters to get the values in the current state. The parameter 'Properties' is used to specify the properties 'Name','Status' and 'StartType' for the comparison.
A hashtable with the current values on the system, obtained by e.g. Get-TargetResource.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The hashtable of desired values. For example $PSBoundParameters with the desired values.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This is a list of which properties in the desired values list should be checked. If this is empty then all values in DesiredValues are checked.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Indicates that result adds the properties in the desired state. By default, this command returns only the properties not in desired state.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Indicates that result contains the ActualValue and ExpectedValue properties.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This is a list of properties in the desired values list should be checked. If this is empty then all values in DesiredValues are checked.
Type: String[]
Parameter Sets: (All)
Aliases: ValuesToCheck
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Indicates that a reverse check should be done. The current and desired state are swapped for another test.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
If the sorting of array values does not matter, values are sorted internally before doing the comparison.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Indicates that the type of the parameter should not be checked.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Returns an array containing a PSCustomObject with metadata for each property that was evaluated.
Metadata Name | Type | Description |
---|---|---|
Property | [System.String] |
The name of the property that was evaluated |
InDesiredState | [System.Boolean] |
Returns $true if the expected and actual value was equal. |
ExpectedType | [System.String] |
Return the type of desired object. |
ActualType | [System.String] |
Return the type of current object. |
ExpectedValue | [System.PsObject] |
Return the value of expected object. |
ActualValue | [System.PsObject] |
Return the value of current object. |
- Assert-BoundParameter
- Assert-ElevatedUser
- Assert-IPAddress
- Assert-Module
- Compare-DscParameterState
- Compare-ResourcePropertyState
- ConvertFrom-DscResourceInstance
- ConvertTo-CimInstance
- ConvertTo-HashTable
- Find-Certificate
- Get-ComputerName
- Get-DscProperty
- Get-EnvironmentVariable
- Get-LocalizedData
- Get-LocalizedDataForInvariantCulture
- Get-PSModulePath
- Get-TemporaryFolder
- Get-UserName
- New-ArgumentException
- New-ErrorRecord
- New-Exception
- New-InvalidDataException
- New-InvalidOperationException
- New-InvalidResultException
- New-NotImplementedException
- New-ObjectNotFoundException
- Remove-CommonParameter
- Set-DscMachineRebootRequired
- Set-PSModulePath
- Test-AccountRequirePassword
- Test-DscParameterState
- Test-DscProperty
- Test-IsNanoServer
- Test-IsNumericType
- Test-ModuleExist