Skip to content

Commit

Permalink
ScheduledTask: Fixed execution account missing domain name (#356)
Browse files Browse the repository at this point in the history
* Fixed execution account missing domain name

* Prevented an issue when the scheduled task is not yet created.

* Update to changelog

* Merge branch 'master' into fix-missing-domain-name

* Reduced line length

* Merge branch 'fix-missing-domain-name' of https://github.com/jensotto/ComputerManagementDsc into fix-missing-domain-name

* Fixed a typo that was not supposed to be commited
  • Loading branch information
jensotto authored Apr 9, 2021
1 parent 307bcb8 commit e181574
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e181574

Please sign in to comment.