DSC - schedules task

Hello all,

 

I would like to used DSC to create some scheduled task.

 

I arrive to create some schedule task with .mof file but I would like to generate an .mof file since a .csv file.

 

Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = ‘localhost’
)

Import-DscResource -ModuleName ComputerManagementDsc

Node $NodeName
{

$import = import-csv -path c:\temp\sctask.csv -delimiter “;”

 

foreach ($lineimport in $import$

{
ScheduledTask ScheduledTaskOnceAdd
{
TaskName = ‘$lineimport.TaskName’
TaskPath = “”+’$lineimport.TaskPath’
ActionExecutable = ‘$lineimport.ActionExecutable’
ScheduleType = ‘$lineimport.ScheduleType’
RepeatInterval = ‘$lineimport.RepeatInterval’
RepetitionDuration = ‘$lineimport.RepetitionDuration’
ExecutionTimeLimit = ‘$lineimport.ExecutionTimeLimit’
ActionWorkingPath = $lineimport.PathActionWorkingPath
Enable = $true
RandomDelay = ‘$lineimport.RandomDelay’
DisallowHardTerminate = $true
RunOnlyIfIdle = $false
Priority = 9
}
}

}

}

 

thank you for your help

You have to name the configuration unique, something like

ScheduledTask $LineImport.TaskName
{
TaskName = $lineimport.TaskName
TaskPath = “\$($lineimport.TaskPath)"
...
...
}

you cannot use single quotes to wrap variables and to access property of an object inside double quotes, a sub expression $() has to be used.