To the DSC pros, this may seem like a very simple question but I couldn't find any resources on the web for this, or for any of the error messages I've seen. It seems very difficult to dig up any information on DSC so perhaps we can start here.
I am trying to build a Powershell DSC configuration for installing a scheduled task. I have found a sample resource on Steve Murawski's Github page for StackExchange resources, and I have copied the 'StackExchangeResources' tree to my DSC repository.
I imported the StackExchangeModule and attempted to create a very simple configuration using the ScheduledTask resource:
Import-Module StackExchangeResources
Configuration TempCleaner
{
param($NodeName)
Node $NodeName
{
$filePath = "C:\Tasks\TempCleaner.ps1";
ScheduledTask
{
Name = "Clear Temporary Files"
FilePath = $filePath
Daily = $true
FilePath = ""
Hours = 4
Minutes = 0
}
}
}
However, when I execute TempCleaner -Node TestNode
, it doesn't actually do anything; no MOF files are written and no errors are thrown.
Now, a lot of examples I've seen involve giving a name to the invocation of the resource, something like this:
File TempCleaner
{
DestinationPath = $filePath
Contents = $(cat $tempCleanerScript | out-string)
Checksum = "SHA-512"
}
But when I try to give it a name like so,
ScheduledTask CleanerTask
{
Name = "Clear Temporary Files"
FilePath = $filePath
Daily = $true
FilePath = ""
Hours = 4
Minutes = 0
}
it will throw an exception:
ScheduledTask : No MSFT_ScheduledTask objects found with property 'TaskName' equal to
'CleanerTask'. Verify the value of the property and retry.
At C:\Users\Steve\Documents\DevOps\DSC\TempCleaner.ps1:13 char:9
+ ScheduledTask CleanerTask
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CleanerTask:String) [Get-ScheduledTask]
, CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_TaskName,Get-ScheduledTask
When I use the scheduled task resource in conjunction with the file resource as shown above, the file resource is written into the resulting MOF file but no other directives can be seen within.
There must be something I'm missing here. Is there some sort of verbose mode I can enable perhaps? Other logging options that aren't documented? That would be very helpful.