diff --git a/scripts/Set-SguDomainUserPolicies.ps1 b/scripts/Set-SguDomainUserPolicies.ps1 index fd62c25..9b3dbc0 100644 --- a/scripts/Set-SguDomainUserPolicies.ps1 +++ b/scripts/Set-SguDomainUserPolicies.ps1 @@ -10,6 +10,7 @@ $ErrorActionPreference = 'Stop' $policyKey = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System' $policyValueName = 'DisableLockWorkstation' $desktopPolicyKey = 'HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop' +$themeKey = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = [Security.Principal.WindowsPrincipal]::new($identity) @@ -83,6 +84,19 @@ if ($PSCmdlet.ShouldProcess($GpoName, 'Prevent SGU users from manually locking w -Type String ` -Value '0' | Out-Null + # Apply the native Windows dark theme at user logon. Both values are required: + # one controls the shell and the other controls supported applications. + foreach ($themeValueName in 'AppsUseLightTheme', 'SystemUsesLightTheme') { + Set-GPRegistryValue ` + -Name $GpoName ` + -Domain $domainName ` + -Server $DomainController ` + -Key $themeKey ` + -ValueName $themeValueName ` + -Type DWord ` + -Value 0 | Out-Null + } + if ($WallpaperPath) { Set-GPRegistryValue ` -Name $GpoName ` @@ -115,6 +129,18 @@ $screenSaverValue = Get-GPRegistryValue ` -Server $DomainController ` -Key $desktopPolicyKey ` -ValueName 'ScreenSaveActive' +$appsThemeValue = Get-GPRegistryValue ` + -Name $GpoName ` + -Domain $domainName ` + -Server $DomainController ` + -Key $themeKey ` + -ValueName 'AppsUseLightTheme' +$systemThemeValue = Get-GPRegistryValue ` + -Name $GpoName ` + -Domain $domainName ` + -Server $DomainController ` + -Key $themeKey ` + -ValueName 'SystemUsesLightTheme' $link = @(Get-GPInheritance -Target $TargetOuDn -Domain $domainName -Server $DomainController).GpoLinks | Where-Object DisplayName -eq $GpoName | Select-Object -First 1 @@ -138,5 +164,6 @@ if ($WallpaperPath) { LinkEnabled = [bool]$linkEnabled DisableLockWorkstation = [int]$configuredValue.Value ScreenSaverDisabled = [string]$screenSaverValue.Value -eq '0' + DarkMode = ([int]$appsThemeValue.Value -eq 0) -and ([int]$systemThemeValue.Value -eq 0) Wallpaper = $configuredWallpaper }