Tests that all the properties on a resource and object are the same.
Test-DscTargetResource [-TargetResource] <Hashtable> [-DesiredResource] <Hashtable> [-Target] <String> [<CommonParameters>]
DSC expects a resource's
Test-TargetResource function to return
$false if an object needs to be updated. Usually, you compare the current state of a resource with the desired state, and return
$false if anything doesn't match.
This function takes in a hashtable of the current resource's state (what's returned by
Get-TargetResource) and compares it to the desired state (the values passed to
Test-TargetResource). If any property in the target resource is different than the desired resource, a list of stale resources is written to the verbose stream and
$false is returned.
Here's a quick example:
return Test-TargetResource -TargetResource (Get-TargetResource -Name 'fubar') -DesiredResource $PSBoundParameters -Target ('my resource ''fubar''')
If you want to exclude properties from the evaluation, just remove them from the hashtable returned by
$resource = Get-TargetResource -Name 'fubar' $resource.Remove( 'PropertyThatDoesNotMatter' ) return Test-TargetResource -TargetResource $resource -DesiredResource $PSBoundParameters -Target ('my resource ''fubar''')
Test-DscTargetResource is new in Carbon 2.0.
|Name||Type||Description||Required?||Pipeline Input||Default Value|
The current state of the resource.
The desired state of the resource. Properties not in this hashtable are skipped. Usually you'll pass
The a description of the target object being tested. Output in verbose messages.
Test-TargetResource -TargetResource (Get-TargetResource -Name 'fubar') -DesiredResource $PSBoundParameters -Target ('my resource ''fubar''')
Demonstrates how to test that all the properties on a DSC resource are the same was what's desired.