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: Specifying BuiltInAccount = 'SYSTEM' will fail DSC test #317

Closed
DennisL68 opened this issue Mar 18, 2020 · 2 comments
Closed
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@DennisL68
Copy link

DennisL68 commented Mar 18, 2020

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

Tried creating a scheduled task running with builtin account SYSTEM.

The task is created succesfully but listed as ResourceNotInDesiredState

Verbose logs showing the problem

Test-DscConfiguration -Detailed -Verbose

Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = TestConfiguration,'className' = 
MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
An LCM method call arrived from computer CLIENT with user sid S-1-5-21-2550973943-1965520939-3234002811-1001.
[CLIENT]: LCM:  [ Start  Test     ]
[CLIENT]: LCM:  [ Start  Resource ]  [[ScheduledTask]CleanUpLogs]
[CLIENT]: LCM:  [ Start  Test     ]  [[ScheduledTask]CleanUpLogs]
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Testing scheduled task 'Cleanup WFM Logs' in '\WFM\'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Getting current scheduled task values for task 
'Cleanup WFM Logs' in '\WFM\'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Task 'Cleanup WFM Logs' found in '\WFM\'. Retrieving 
settings, first action, first trigger and repetition settings.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Detected schedule type 'Daily' for first trigger.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Current scheduled task values for task 'Cleanup WFM 
Logs' in '\WFM\' retrieved.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Testing DSC parameter state.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'ActionArguments' does match. Current state is '-Command "ls $ENV:TEMP -File -Recursive | 
                where {((Get-Date) - $_.LastWriteTime).Minutes -gt 1} |
                Remove-Item -Confirm:$false -Force"' and desired state is '-Command "ls $ENV:TEMP -File -Recursive | 
                where {((Get-Date) - $_.LastWriteTime).Minutes -gt 1} |
                Remove-Item -Confirm:$false -Force"'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'ActionExecutable' does match. Current state is '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe' and 
desired state is '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'TaskName' does match. Current state is 'Cleanup WFM Logs' and desired state is 'Cleanup WFM Logs'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'TaskPath' does match. Current state is '\WFM\' and desired state is '\WFM\'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'User' does match. Current state is 'SYSTEM' and desired state is 'SYSTEM'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'Ensure' does match. Current state is 'Present' and desired state is 'Present'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] NOTMATCH: Value (type 'System.String') for property 
'BuiltInAccount' does not match. Current state is 'NT AUTHORITY\SYSTEM' and desired state is 'SYSTEM'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.Boolean') for property 
'StartWhenAvailable' does match. Current state is 'True' and desired state is 'True'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'StartTime' does match. Current state is '2020-03-18T21:00:00' and desired state is '2020-03-18T21:00:00'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'LogonType' does match. Current state is 'ServiceAccount' and desired state is 'ServiceAccount'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.Boolean') for property 
'Enable' does match. Current state is 'True' and desired state is 'True'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'ScheduleType' does match. Current state is 'Daily' and desired state is 'Daily'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] MATCH: Value (type 'System.String') for property 
'ExecuteAsCredential' does match. Current state is 'SYSTEM' and desired state is 'SYSTEM'.
[CLIENT]:                            [[ScheduledTask]CleanUpLogs] Test-DscParameter result is 'False'.
[CLIENT]: LCM:  [ End    Test     ]  [[ScheduledTask]CleanUpLogs] False in 1.1720 seconds.
[CLIENT]: LCM:  [ End    Resource ]  [[ScheduledTask]CleanUpLogs]
[CLIENT]: LCM:  [ End    Test     ]     Completed processing test operation. The operation returned False.
[CLIENT]: LCM:  [ End    Test     ]    in  1.6560 seconds.
Operation 'Invoke CimMethod' complete.

PSComputerName  ResourcesInDesiredState        ResourcesNotInDesiredState     InDesiredState 
--------------  -----------------------        --------------------------     -------------- 
localhost                                      {[ScheduledTask]CleanUpLogs}   False          
Time taken for configuration job to complete is 1.774 seconds

Suggested solution to the issue

The resource only accepts 'SYSTEM' as input. But Scheduled task actually converts this to 'NT AUTHORITY\SYSTEM'

Please have the MOF created with 'NT AUTHORITY\SYSTEM' instead of 'SYSTEM' when specifying BuiltInAccount = 'SYSTEM' and have the resource accept the entry.

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

Configuration Config-HandleLogSize {
    Import-DscResource -ModuleName ComputerManagementDsc

    Node localhost {

        ScheduledTask 'CleanUpLogs' {
            TaskName = 'Cleanup WFM Logs'
            TaskPath = '\WFM'
            ActionExecutable = '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'
            ActionArguments = '-Command "ls $ENV:TEMP -File -Recursive | 
                where {((Get-Date) - $_.LastWriteTime).Minutes -gt 1} |
                Remove-Item -Confirm:$false -Force"'
            ScheduleType = 'Daily'
            StartTime = '21:00'
            StartWhenAvailable = $true
            Enable = $true
            Ensure = 'Present'
            BuiltInAccount = 'SYSTEM'
        }

    }#end localhost
    
}#end HandleLogSize

The operating system the target node is running

OsName               : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 1909
WindowsBuildLabEx    : 18362.1.amd64fre.19h1_release.190318-1202
OsLanguage           : en-GB
OsMuiLanguages       : {en-GB}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.18362.628
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.628
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)

Get-Module ComputerManagementDsc -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   8.0.0      ComputerManagementDsc
@DennisL68
Copy link
Author

Proposed fix is available in #313

@PlagueHO PlagueHO added bug The issue is a bug. in progress The issue is being actively worked on by someone. labels Mar 22, 2020
@PlagueHO
Copy link
Member

This has been merged, so will close. I'll release a new version of this module shortly.

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. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

No branches or pull requests

2 participants