Compare commits

..
1 Commits
Author SHA1 Message Date
alexrg ac531db05e Apply dark theme through user policy 2026-09-04 10:11:32 -06:00
+27
View File
@@ -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
}