Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ykuijs opened this issue Feb 20, 2020 · 0 comments
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@ykuijs
Copy link
Member

ykuijs commented Feb 20, 2020

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):

if ($currentValues.Ensure -eq 'Present' `
-and $currentValues.Enable `
-and -not $Enable `
-and -not $PSBoundParameters.ContainsKey('ActionExecutable'))

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

@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants