diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee2d68c..61d74daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed issue with disabling scheduled tasks that have "Run whether user is logged on or not" configured - Fixes [Issue #306](https://github.com/dsccommunity/ComputerManagementDsc/issues/306). - Fixed issue with `ExecuteAsCredential` not returning fully qualified username - on newer versions of Windows 10 and Windows Server 2019 - Fixes [Issue #352](https://github.com/dsccommunity/ComputerManagementDsc/issues/352). + on newer versions of Windows 10 and Windows Server 2019 for both local + accounts and domain accounts - Fixes [Issue #352](https://github.com/dsccommunity/ComputerManagementDsc/issues/352). - Fixed issue with `StartTime` failing Test-Resource if not specified in the resource - Fixes [Issue #148](https://github.com/dsccommunity/ComputerManagementDsc/issues/148). - PendingReboot diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 6d56125e..51abe5ab 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1448,9 +1448,18 @@ function Test-TargetResource To resolve this, add the computer name if it is missing and if it was passed in the ExecuteAsCredential parameter. #> - if ($username -cmatch '\\' -and $currentValues.ExecuteAsCredential -cnotmatch '\\') + if ($username -match "$ENV:COMPUTERNAME\\" -and $currentValues.ExecuteAsCredential) { - $currentValues.ExecuteAsCredential = "$ENV:COMPUTERNAME\$($currentValues.ExecuteAsCredential)" + $currentValues.ExecuteAsCredential = Set-DomainNameInAccountName ` + -AccountName $currentValues.ExecuteAsCredential ` + -DomainName $ENV:COMPUTERNAME + } + + if ($username -match "$ENV:USERDOMAIN\\" -and $currentValues.ExecuteAsCredential) + { + $currentValues.ExecuteAsCredential = Set-DomainNameInAccountName ` + -AccountName $currentValues.ExecuteAsCredential ` + -DomainName $ENV:USERDOMAIN } } else