Skip to content

Commit

Permalink
Fix PendingReboot Localized Data issue - Fixes #350 (#351)
Browse files Browse the repository at this point in the history
- ScheduleTask
  - Fixed issue with `ExecuteAsCredential` not returning fully qualified username
    on newer versions of Windows 10 and Windows Server 2019 - Fixes Issue #352.
- PendingReboot
  - Fixed issue with loading localized data on non en-US operating systems -
    Fixes Issue #350.
  • Loading branch information
PlagueHO authored Feb 7, 2021
1 parent 1e924d6 commit ae1e1bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ScheduledTask
- 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).
- PendingReboot
- Fixed issue with loading localized data on non en-US operating systems -
Fixes [Issue #350](https://github.com/dsccommunity/ComputerManagementDsc/issues/350).

## [8.4.0] - 2020-08-03

Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
when determining if reboot is required. This is stored in a separate
data file so that it can also be used in testing.
#>
$script:localizedResourceData = Import-LocalizedData `
-BaseDirectory $PSScriptRoot `
-FileName 'DSC_PendingReboot.data.psd1'
$script:localizedResourceData = Get-LocalizedData `
-DefaultUICulture 'en-US' `
-FileName 'DSC_PendingReboot.data'
$script:rebootTriggers = $script:localizedResourceData.RebootTriggers
<#
.SYNOPSIS
Expand Down
22 changes: 18 additions & 4 deletions source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,19 @@ function Test-TargetResource
# The password of the execution credential can not be compared
$username = $ExecuteAsCredential.UserName
$PSBoundParameters['ExecuteAsCredential'] = $username

<#
Windows Server 2019 and newer versions of Windows 10 don't return fully qualified
username in the current ExecuteAsCredential if it is the local machine. Therefore
the compare will fail and show a false positive (see Issue #350).
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 '\\')
{
$currentValues.ExecuteAsCredential = "$ENV:COMPUTERNAME\$($currentValues.ExecuteAsCredential)"
}
}
else
{
Expand Down Expand Up @@ -1832,11 +1845,12 @@ function Get-CurrentResource
$PrincipalId = 'UserId'
}

<# The following workaround is needed because Get-StartedTask currently returns NULL for the value
of $settings.MultipleInstances when the started task is set to "Stop the existing instance".
https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/40685125-bug-get-scheduledtask-returns-null-for-value-of-m
#>
<# The following workaround is needed because Get-StartedTask currently returns NULL for the value
of $settings.MultipleInstances when the started task is set to "Stop the existing instance".
https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/40685125-bug-get-scheduledtask-returns-null-for-value-of-m
#>
$MultipleInstances = [System.String] $settings.MultipleInstances

if ([System.String]::IsNullOrEmpty($MultipleInstances))
{
if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3)
Expand Down

0 comments on commit ae1e1bf

Please sign in to comment.