@@ -792,7 +792,7 @@ function Set-TargetResource
792792 non-null value to be 'LOCAL SERVICE', 'NETWORK SERVICE' or
793793 'SYSTEM'
794794 #>
795- $username = ' NT AUTHORITY\ ' + $BuiltInAccount
795+ $username = Set-DomainNameInAccountName - AccountName $BuiltInAccount - DomainName ' NT AUTHORITY'
796796 $registerArguments.Add (' User' , $username )
797797 $LogonType = ' ServiceAccount'
798798 }
@@ -804,7 +804,6 @@ function Set-TargetResource
804804 elseif ($PSBoundParameters.ContainsKey (' ExecuteAsCredential' ))
805805 {
806806 $username = $ExecuteAsCredential.UserName
807-
808807 # If the LogonType is not specified then set it to password
809808 if ([System.String ]::IsNullOrEmpty($LogonType ))
810809 {
@@ -829,7 +828,7 @@ function Set-TargetResource
829828 privileges, should we default to 'NT AUTHORITY\LOCAL SERVICE'
830829 instead?
831830 #>
832- $username = ' NT AUTHORITY\SYSTEM '
831+ $username = Set-DomainNameInAccountName - AccountName ' SYSTEM ' - DomainName ' NT AUTHORITY'
833832 $registerArguments.Add (' User' , $username )
834833 $LogonType = ' ServiceAccount'
835834 }
@@ -1423,16 +1422,17 @@ function Test-TargetResource
14231422
14241423 if ($PSBoundParameters.ContainsKey (' BuiltInAccount' ))
14251424 {
1426- $PSBoundParameters.User = $BuiltInAccount
1427- $currentValues.User = $BuiltInAccount
1425+ $user = Set-DomainNameInAccountName - AccountName ' SYSTEM' - DomainName ' NT AUTHORITY'
1426+ $PSBoundParameters.User = $user
1427+ $currentValues.User = $user
14281428
14291429 $PSBoundParameters.ExecuteAsCredential = $BuiltInAccount
14301430 $currentValues.ExecuteAsCredential = $BuiltInAccount
14311431
14321432 $PSBoundParameters [' LogonType' ] = ' ServiceAccount'
14331433 $currentValues [' LogonType' ] = ' ServiceAccount'
14341434
1435- $PSBoundParameters [' BuiltInAccount' ] = ' NT AUTHORITY\ ' + $BuiltInAccount
1435+ $PSBoundParameters [' BuiltInAccount' ] = $BuiltInAccount
14361436 }
14371437 elseif ($PSBoundParameters.ContainsKey (' ExecuteAsCredential' ))
14381438 {
@@ -1464,6 +1464,16 @@ function Test-TargetResource
14641464 }
14651465 else
14661466 {
1467+ $user = Set-DomainNameInAccountName - AccountName ' SYSTEM' - DomainName ' NT AUTHORITY'
1468+ $PSBoundParameters.User = $user
1469+ $currentValues.User = $user
1470+
1471+ $PSBoundParameters.ExecuteAsCredential = ' SYSTEM'
1472+ $currentValues.ExecuteAsCredential = ' SYSTEM'
1473+
1474+ $PSBoundParameters.Add (' BuiltInAccount' , $BuiltInAccount )
1475+ $currentValues.BuiltInAccount = $BuiltInAccount
1476+
14671477 # Must be running as System, login type is ServiceAccount
14681478 $PSBoundParameters [' LogonType' ] = ' ServiceAccount'
14691479 $currentValues [' LogonType' ] = ' ServiceAccount'
@@ -1915,9 +1925,15 @@ function Get-CurrentResource
19151925 Delay = ConvertTo-TimeSpanStringFromScheduledTaskString - TimeSpan $trigger.Delay
19161926 }
19171927
1918- if (($result.ContainsKey (' LogonType' )) -and ($result [' LogonType' ] -ieq ' ServiceAccount' ))
1928+ if (
1929+ (($result.ContainsKey (' LogonType' )) -and ($result [' LogonType' ] -ieq ' ServiceAccount' )) -or
1930+ $result.Principal.UserID -in @ (' SYSTEM' , ' LOCAL SERVICE' , ' NETWORK SERVICE' )
1931+ )
19191932 {
1920- $builtInAccount = Set-DomainNameInAccountName - AccountName $task.Principal.UserId - DomainName ' NT AUTHORITY'
1933+ $result.User = Set-DomainNameInAccountName `
1934+ - AccountName $task.Principal.UserId `
1935+ - DomainName ' NT AUTHORITY'
1936+ $builtInAccount = $task.Principal.UserId
19211937 $result.Add (' BuiltInAccount' , $builtInAccount )
19221938 }
19231939 }
0 commit comments