dsccommunity / dsccommunity/ComputerManagementDsc

[ScheduledTask] Resource throws errors when task does not exists, but not all parameters are provided

Open
#311 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
PowerShell
Stars
338
Forks
80
PR merge metrics
No merged PRs in 30d

Description

Details of the scenario you tried and the problem that is occurring

I am trying to disable a scheduled task and using the below config for this. Since I am only interested in disabling the scheduled task, I do not provide any of the Action* parameters like ActionExecutable.

During some testing, I ran into a situation where my scheduled task wasn't properly created. When the ScheduledTask resource then ran, it threw some errors. If skipped the first check in the Set-TargetResource method, because the currentValues.Enable parameters wasn't True (since it didn't exist): https://github.com/dsccommunity/ComputerManagementDsc/blob/5a6d8557dac06e7a6dbea3f973f34aff3f060cd6/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1#L451-L454

The code then tried to create a new task, which failed because I wasn't providing any of the Action parameters.

Verbose logs showing the problem
VERBOSE: [SERVER]:                            [[ScheduledTask]DisableWFSchedTask] Current scheduled task values for task 'Workflow Manager 1.0 CEIP Uploader Task' in '\Microsoft\Windows\PowerShell\ScheduledJobs\' retrieved.
Cannot validate argument on parameter 'Execute'. The argument is null or empty. Provide an argument that is not null or
 empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,New-ScheduledTaskAction
    + PSComputerName        : localhost

PowerShell Desired State Configuration does not support execution of commands in an interactive mode. Please ensure that the underlying command is not prompting for user input, such as missing mandatory parameter, confirmation prompt etc.
    + CategoryInfo          : NotSpecified: (:) [], CimException
    + FullyQualifiedErrorId : RemoteHostExecutionException
    + PSComputerName        : localhost

Cannot validate argument on parameter 'ErrorRecord'. The argument is null. Provide a valid value for the argument, and then try running the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,New-InvalidOperationException
    + PSComputerName        : localhost

You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : InvokeMethodOnNull
    + PSComputerName        : localhost

VERBOSE: [SERVER]:                            [[ScheduledTask]DisableWFSchedTask] Creating scheduled task principal for account 'NT AUTHORITY\SYSTEM' using logon type 'ServiceAccount'.
Cannot validate argument on parameter 'Action'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,New-ScheduledTask
    + PSComputerName        : localhost

VERBOSE: [SERVER]:                            [[ScheduledTask]DisableWFSchedTask] Creating new scheduled task 'Workflow Manager 1.0 CEIP Uploader Task' in '\Microsoft\Windows\PowerShell\ScheduledJobs\'.
Cannot index into a null array.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NullArray
    + PSComputerName        : localhost

VERBOSE: [SERVER]:                            [[ScheduledTask]DisableWFSchedTask] Creating new scheduled task 'Workflow Manager 1.0 CEIP Uploader Task' in '\Microsoft\Windows\PowerShell\ScheduledJobs\'.
Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Register-ScheduledTask
    + PSComputerName        : localhost

VERBOSE: [SERVER]: LCM:  [ End    Set      ]  [[ScheduledTask]DisableWFSchedTask]  in 1.4690 seconds.
The PowerShell DSC resource '[ScheduledTask]DisableWFSchedTask' with SourceInfo 'C:\SPSources\2019\Configs\Deploy_SharePoint.ps1::1751::17::ScheduledTask' threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost
Suggested solution to the issue

I think it would be good to add some parameter validation. If the code tries to create a new task, it should validate if the Action parameters are provided.

The DSC configuration that is used to reproduce the issue (as detailed as possible)
ScheduledTask 'DisableWFSchedTask'
{
    TaskName             = 'Workflow Manager 1.0 CEIP Uploader Task'
    TaskPath             = '\Microsoft\Windows\PowerShell\ScheduledJobs'
    Enable               = $false
    PsDscRunAsCredential = $InstallAccount
    DependsOn            = '[WorkflowManagerFarm]WFFarmConfig'
}
The operating system the target node is running

OsName : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.3503.amd64fre.rs1_release.200131-0410
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.14393.3471
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3471
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

7.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1, especially the Set-TargetResource logic around lines 451-454. Reproduce the case with the provided ScheduledTask configuration and verify that a missing task with no Action parameters produces a clear validation error instead of cascading PowerShell errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.