Open ShawnHardwick opened 5 years ago
Thanks for raising this @ShawnHardwick.
Are you able to share the DSC Config you're using (with specifics redacted)? @johlju - do you recall what the exact cause of this problem was over in SqlServerDsc?
In the SqlServerDsc case it was a parameter that set a default value from another parameter
param
(
[Parameter(Mandatory = $true)]
[System.String]
$InstanceName
[Parameter()]
[System.String]
$FailoverClusterGroupName = "SQL Server ($InstanceName)"
)
It failed on $FailoverClusterGroupName = "SQL Server ($InstanceName)"
.
Maybe it fails on this?
The solution was to set the default value as the first thing in the code, instead of setting it in the param block.
@PlagueHO
I actually use Puppet to call DSC so I'll provide what Puppet calls and what I call directly to debug the code.
$invokeParams = @{
Name = 'ScheduledTask'
Method = 'test'
Property = @{
taskname = 'OneDrive Mapper'
actionexecutable = 'C:\OneDrive_Mapper\OneDrive_Mapper.exe'
scheduletype = 'AtLogOn'
enable = $true
delay = '00:00:30'
}
$result = Invoke-DscResource @invokeParams
@ShawnHardwick to just rule this out. In these locations can you remove the = [System.DateTime]::Today
from all three locations in the resource code on your node.
Than in the start of each function Get-TargetResource, Test-TargetResource and Set-TargetResource please add these rows. Alternative to adding the below rows, you could add the StartTime
parameter with a valid value to the properties that you call Puppet with.
if (-not $PSBoundParameters.ContainsKey('StartTime'))
{
$StartTime = [System.DateTime]::Today
}
This is the only thing I can see that is close to the problem in SqlServerDsc, it would be nice to rule it out.
That appears to have fixed it. I can use Enable-DSCDebug -BreakAll
to open a debugger in DSC now with the ScheduledTask resource.
It's interesting to know now that the DSC debug fails if the default value for a parameter needs to be derived from a function or another parameter.
Just curious, if this has been broken for this resource, how do other people step through DSC code?
Thanks @johlju - great info. I'll look at incorporating changes into the resource over the weekend.
@ShawnHardwick , in answer to your question, I very rarely use DSC debugging, generally relying on unit tests/integration tests. I try to use a red-green refactor (TDD) approach when writing resources. This doesn't eliminate the need for debugging, but does make it a rare enough occurrence.
I'm not completely sure why the conditions @johlju identified would have caused problems debugging DSC, but I'll look into it a bit more. Might also be something we can test for as well.
Details of the scenario you tried and the problem that is occurring
Enabling DSC debug with
Enable-DSCDebug -BreakAll
and then running the ScheduledTask resource returns an error:Verbose logs showing the problem
Suggested solution to the issue
See the below issue for the same problem in a different DSC module: https://github.com/PowerShell/SqlServerDsc/issues/448
The DSC configuration that is used to reproduce the issue (as detailed as possible)
No configuration to provide
The operating system the target node is running
Version and build of PowerShell the target node is running
Version of the DSC module that was used ('dev' if using current dev branch)
6.4.0.0