< Back
Test-CDscTargetResource
Post
NAME Test-CDscTargetResource
SYNOPSIS
Tests that all the properties on a resource and object are the same.
SYNTAX
Test-CDscTargetResource [-TargetResource] <Hashtable> [-DesiredResource] <Hashtable> [-Target] <String>
[<CommonParameters>]
DESCRIPTION
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
`Get-TargetResource`:
$resource = Get-TargetResource -Name 'fubar'
$resource.Remove( 'PropertyThatDoesNotMatter' )
return Test-TargetResource -TargetResource $resource -DesiredResource $PSBoundParameters -Target ('my resource
''fubar''')
`Test-CDscTargetResource` is new in Carbon 2.0.
PARAMETERS
-TargetResource <Hashtable>
The current state of the resource.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DesiredResource <Hashtable>
The desired state of the resource. Properties not in this hashtable are skipped. Usually you'll pass
`PSBoundParameters` from your `Test-TargetResource` function.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Target <String>
The a description of the target object being tested. Output in verbose messages.
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Boolean.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>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.
RELATED LINKS
SYNOPSIS
Tests that all the properties on a resource and object are the same.
SYNTAX
Test-CDscTargetResource [-TargetResource] <Hashtable> [-DesiredResource] <Hashtable> [-Target] <String>
[<CommonParameters>]
DESCRIPTION
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
`Get-TargetResource`:
$resource = Get-TargetResource -Name 'fubar'
$resource.Remove( 'PropertyThatDoesNotMatter' )
return Test-TargetResource -TargetResource $resource -DesiredResource $PSBoundParameters -Target ('my resource
''fubar''')
`Test-CDscTargetResource` is new in Carbon 2.0.
PARAMETERS
-TargetResource <Hashtable>
The current state of the resource.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DesiredResource <Hashtable>
The desired state of the resource. Properties not in this hashtable are skipped. Usually you'll pass
`PSBoundParameters` from your `Test-TargetResource` function.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Target <String>
The a description of the target object being tested. Output in verbose messages.
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Boolean.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>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.
RELATED LINKS