The Test method is used to determine whether Set should be run. DSC invokes Test before Set. The Test method returns a Boolean value.
The Test method must perform the following tests to ascertain the state of this configuration item:
- When Ensure is present, fail if the value does not exist.
- When Ensure is present, fail if the value exists, but the description does not match the requested value.
- When Ensure is absent, fail if the value name exists.
- Otherwise, pass.
The following snippet implements these tests:
[Boolean] Test() {
$key = Get-Item $this.Path
if ($this.Ensure -eq 'Present') {
if ($key.GetValueNames() -notcontains $this.valueName) {
return $false
}
return $key.GetValue($this.valueName) -eq $this.Description
} else {
return $key.GetValueNames() -notcontains $this.valueName
}
return $true
}
Each of these methods must be copied back into the resource class.