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] Disabling scheduled task fails with incorrect user name or password error #306

Closed
ykuijs opened this issue Feb 7, 2020 · 4 comments · Fixed by #346
Closed
Labels
help wanted The issue is up for grabs for anyone in the community. needs investigation The issue needs to be investigated by the maintainers or/and the community.

Comments

@ykuijs
Copy link
Member

ykuijs commented Feb 7, 2020

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

I try to disable a scheduled task using the ScheduledTask resource. Unfortunately this results in the error "The user name or password is incorrect.", thrown by the Register-ScheduledTask cmdlet.

I have been able to track this back to the following lines:

$existingTask = ScheduledTasks\Get-ScheduledTask @PSBoundParameters
$existingTask.Settings.Enabled = $false
$null = $existingTask | Register-ScheduledTask @PSBoundParameters -Force

Verbose logs showing the problem

Suggested solution to the issue

Why is is there a custom Disable-ScheduledTask function? When I remove this, so PowerShell reverts back to the default Disable-ScheduledTask cmdlet, it works as expected.

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
}

The operating system the target node is running

Windows Server 2016 with all most recent patches

Version and build of PowerShell the target node is running

v5.1

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

7.1.0.0 and dev

@ykuijs
Copy link
Member Author

ykuijs commented Feb 7, 2020

There is something specific with this task. I am just unable to disable this specific task. When I run the following commands, the same error is displayed

$taskname = "Workflow Manager 1.0 CEIP Uploader Task"
$taskpath = "\Microsoft\Windows\PowerShell\ScheduledJobs\"

$task = ScheduledTasks\Get-ScheduledTask -TaskName $taskname -TaskPath $taskpath
$task.Settings.Enabled = $false
$task | Register-ScheduledTask -TaskName $taskname -TaskPath $taskpath -Force

Register-ScheduledTask : The user name or password is incorrect.
At line:6 char:9
+ $task | Register-ScheduledTask -TaskName $taskname -TaskPath $taskpat ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x8007052e,Register-ScheduledTask

Using the same code for other tasks, they can be disabled just fine.

I am running these commands in an elevated PS process.

@PlagueHO PlagueHO added help wanted The issue is up for grabs for anyone in the community. needs investigation The issue needs to be investigated by the maintainers or/and the community. labels Feb 11, 2020
@PlagueHO
Copy link
Member

Hi @ykuijs - that is pretty odd. What does the Principal property of the task look like? E.g.

$taskname = "Workflow Manager 1.0 CEIP Uploader Task"
$taskpath = "\Microsoft\Windows\PowerShell\ScheduledJobs\"

$task = ScheduledTasks\Get-ScheduledTask -TaskName $taskname -TaskPath $taskpath
$task.Principal

@ykuijs
Copy link
Member Author

ykuijs commented Feb 20, 2020

The Principal is:

DisplayName         : 
GroupId             : 
Id                  : Author
LogonType           : Password
RunLevel            : Limited
UserId              : [DOMAIN]\[USERID]
ProcessTokenSidType : Default
RequiredPrivilege   : 
PSComputerName      : 

@ykuijs
Copy link
Member Author

ykuijs commented Feb 20, 2020

Did some more troubleshooting and discovered that this code always fails when you create a task that has "Run whether user is logged on or not" configured.

The PowerShell native "Disable-ScheduledTask" (PSv5 and above only) works fine on these tasks.

ykuijs added a commit to ykuijs/ComputerManagementDsc that referenced this issue Jul 29, 2020
@ykuijs ykuijs mentioned this issue Jul 29, 2020
9 tasks
ykuijs added a commit to ykuijs/ComputerManagementDsc that referenced this issue Aug 4, 2020
PlagueHO pushed a commit that referenced this issue Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted The issue is up for grabs for anyone in the community. needs investigation The issue needs to be investigated by the maintainers or/and the community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants