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 Credential parameter with Domain\ prefix #294

Closed
ewhitesides opened this issue Dec 3, 2019 · 6 comments · Fixed by #326
Closed

ScheduledTask resource Credential parameter with Domain\ prefix #294

ewhitesides opened this issue Dec 3, 2019 · 6 comments · Fixed by #326
Assignees
Labels
help wanted The issue is up for grabs for anyone in the community. in progress The issue is being actively worked on by someone.

Comments

@ewhitesides
Copy link

ewhitesides commented Dec 3, 2019

I have a job as following, but it reports the state as incorrect because of the credential. It appears I am setting it as 'username' but then the scheduled task is taking that and just setting it as DOMAIN\username, leading to a mismatch. I think I can probably hack it to work somehow, but ideally the scheduledtask resource should probably evaluate DOMAIN\username the same as username.

ScheduledTask 'DRBackup' {
TaskName = 'DRBackup'
TaskPath = '\8203Jobs'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ActionArguments = "-Command $BackupJob_Cmd1 $BackupJob_Cmd2"
ScheduleType = 'Daily'
StartTime = Get-Date '3am'
ExecuteAsCredential = $DomainAdminCred
RunLevel = 'Highest'
DependsOn = '[cPowerShellModuleManagement]EventLogTools','[xEventLog]CustomLog','[cPowerShellModuleManagement]DRBackupTools'
}

Verbose Output from Test
VERBOSE: [NOAA8203-MGMT1]: LCM: [ Start Resource ] [[ScheduledTask]DRBackup]
VERBOSE: [NOAA8203-MGMT1]: LCM: [ Start Test ] [[ScheduledTask]DRBackup]
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Testing scheduled task 'DRBackup' in '\8203Jobs'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Getting current scheduled task values for task 'DRBackup' in '\8203Jobs'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Task 'DRBackup' found in '\8203Jobs'. Retrieving settings, first action, first trigger and repetition
settings.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Detected schedule type 'Daily' for first trigger.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Current scheduled task values for task 'DRBackup' in '\8203Jobs' retrieved.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Testing DSC parameter state.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'StartTime' does match. Current state is
'2019-12-02T03:00:00' and desired state is '2019-12-02T03:00:00'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'ActionExecutable' does match. Current state is
'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' and desired state is 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'ActionArguments' does match. Current state is '-Command
Start-DRBackup -DPMProtectionGroupName DisasterRecovery -Destination \noaa8203-ds1817\DRBackup -Verbose *>&1 | % {$i++;Write-StreamToEventLog -ID $i -Stream $_ -Logname Application
-Source DRBackupTools}' and desired state is '-Command Start-DRBackup -DPMProtectionGroupName DisasterRecovery -Destination \noaa8203-ds1817\DRBackup -Verbose *>&1 | %
{$i++;Write-StreamToEventLog -ID $i -Stream $_ -Logname Application -Source DRBackupTools}'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] NOTMATCH: Value (type 'System.String') for property 'ExecuteAsCredential' does not match. Current state is
'NOAA8203\powershelljobs_svc' and desired state is 'powershelljobs_svc'.

VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'TaskPath' does match. Current state is '\8203Jobs' and
desired state is '\8203Jobs'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'ScheduleType' does match. Current state is 'Daily' and
desired state is 'Daily'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'TaskName' does match. Current state is 'DRBackup' and
desired state is 'DRBackup'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] MATCH: Value (type 'System.String') for property 'RunLevel' does match. Current state is 'Highest' and
desired state is 'Highest'.
VERBOSE: [NOAA8203-MGMT1]: [[ScheduledTask]DRBackup] Test-DscParameter result is 'False'.
VERBOSE: [NOAA8203-MGMT1]: LCM: [ End Test ] [[ScheduledTask]DRBackup] False in 0.5940 seconds.

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

Verbose logs showing the problem

Suggested solution to the issue

The DSC configuration that is used to reproduce the issue (as detailed as possible)

# insert configuration here

The operating system the target node is running

Version and build of PowerShell the target node is running

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

@ewhitesides
Copy link
Author

I flipped it around, I provided 'DOMAIN\username' and now the state is reporting as false, indicating it is looking for just 'username'.

VERBOSE: [NOAA8203-HV3]: [[ScheduledTask]SnapshotCleanup] NOTMATCH: Value (type 'System.String') for property 'ExecuteAsCredential' does not match. Current state is 'powershelljobs_svc' and desired state is 'NOAA8203\powershelljobs_svc'.

@ewhitesides
Copy link
Author

I think I may have solved this - solution was to run OS updates. perhaps something was changed in Task Scheduler, but now the username is lining up when I specify it as DOMAIN\username. will continue to monitor this.

@ewhitesides
Copy link
Author

ewhitesides commented Dec 4, 2019

now seeing the following

It looks like even though I set SynchronizeAcrossTimeZone to be $true, it changes to $false. Then it modifies StartTime, which then tests incorrectly.

ScheduledTask "MarineForecastDownload_pm" {
TaskName = "MarineForecastDownload_pm"
TaskPath = '\8203Jobs'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ActionArguments = "-Command $MarineForecast_Cmd1 $MarineForecast_Cmd2"
ScheduleType = 'Daily'
StartTime = $StartTime
SynchronizeAcrossTimeZone = $true
ExecuteAsCredential = $DomainAdminCred
RunLevel = 'Highest'
DependsOn = '[cPowerShellModuleManagement]EventLogTools','[xEventLog]CustomLog','[cPowerShellModuleManagement]DownloadTools'
}

VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] Testing DSC parameter state.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] NOTMATCH: Value (type 'System.String') for property 'StartTime' does not match. Current
state is '2019-12-04T07:15:00' and desired state is '2019-12-04T07:15:00-05:00'.

VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'ActionExecutable' does match. Current
state is 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' and desired state is 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'ActionArguments' does match. Current
state is '-Command Start-DownloadTools -Product MarineForecast -Verbose *>&1 | % {$i++;Write-StreamToEventLog -Stream $_ -ID $i -LogName Application -Source DownloadTools}' and desired
state is '-Command Start-DownloadTools -Product MarineForecast -Verbose *>&1 | % {$i++;Write-StreamToEventLog -Stream $_ -ID $i -LogName Application -Source DownloadTools}'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'ExecuteAsCredential' does match. Current
state is 'NOAA8203\powershelljobs_svc' and desired state is 'NOAA8203\powershelljobs_svc'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'TaskPath' does match. Current state is
'\8203Jobs' and desired state is '\8203Jobs'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] NOTMATCH: Value (type 'System.Boolean') for property 'SynchronizeAcrossTimeZone' does not
match. Current state is 'False' and desired state is 'True'.

VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'ScheduleType' does match. Current state
is 'Daily' and desired state is 'Daily'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'TaskName' does match. Current state is
'MarineForecastDownload_pm' and desired state is 'MarineForecastDownload_pm'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] MATCH: Value (type 'System.String') for property 'RunLevel' does match. Current state is
'Highest' and desired state is 'Highest'.
VERBOSE: [NOAA8203-APPPR1]: [[ScheduledTask]MarineForecastDownload_pm] Test-DscParameter result is 'False'.
VERBOSE: [NOAA8203-APPPR1]: LCM: [ End Test ] [[ScheduledTask]MarineForecastDownload_pm] False in 0.5310 seconds.

@ewhitesides
Copy link
Author

i solved this by removing SynchronizeAcrossTimeZone = $true

i remember from previous experience that ScheduledTasks by default have the 'Sync across timezone' checkbox checked by default.

Powershell jobs, do not sync across timezones by default.

@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 Dec 16, 2019
@danielboth
Copy link
Member

danielboth commented Dec 18, 2019

I think I may have solved this - solution was to run OS updates. perhaps something was changed in Task Scheduler, but now the username is lining up when I specify it as DOMAIN\username. will continue to monitor this.

Just to share here as well, I also noticed a difference between scheduledtask behaviour on W2016 after recent updates (I think November 2019). On W2016 before November 2019 UserId would be returned as 'USER' after updates, it is returned as 'DOMAIN\User'.

I was unable to find any references in Microsoft changelogs to this bugfix (what I believe it is, as on W2012 it always returned the proper 'DOMAIN\User'), so if anyone has any reference / contact at Microsoft who can confirm this fix, that would be great!

In time, we might want to remove this workaround:

There is a difference in W2012R2 and W2016 behaviour,

@PlagueHO
Copy link
Member

PlagueHO commented May 4, 2020

I've not been able to track this down, but there are many strange behaviors around how UserIds are stored in the Task Scheduler principal object that is returned.

For example, setting the ExecuteAsCredential to 'BUILTIN\Users' (through code or the UI) and it will always return 'Users' in the principal. This occurs in the UI too. However, setting 'DOMAIN\Users' returns the correct value.

I'm not going to try and spend too much time picking this behavior apart because unfortunately ScheduledTask behaves differently in every OS. Instead I'm going to add some information to the Known Issues section with some guidance.

@PlagueHO PlagueHO added in progress The issue is being actively worked on by someone. and removed needs investigation The issue needs to be investigated by the maintainers or/and the community. labels May 4, 2020
@PlagueHO PlagueHO self-assigned this May 4, 2020
PlagueHO added a commit to PlagueHO/ComputerManagementDsc that referenced this issue May 4, 2020
PlagueHO added a commit that referenced this issue May 5, 2020
* Fix Issue #324 and #325
* Fix Issue #323
* Add fix for #294
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. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants