For quite some time now, I have been on the lookout for a solution to change my Windows 11 display from light mode to dark mode. The functionality of switching between these two modes has been a constant desire of mine, as it not only enhances the visual aesthetics but also offers added convenience and benefits.
With the ongoing advancements in technology, many applications and operating systems now provide users with the option to choose their preferred mode, allowing for a more personalized and comfortable user experience. From reducing eye strain and conserving battery life on devices with LED screens to providing a more soothing ambiance during nighttime usage, dark mode has gained immense popularity among individuals across various platforms.
Whether it’s editing documents late at night or browsing social media before bed, having the ability to switch seamlessly between light and dark modes has become an essential feature that I’ve yearned for.
So, I created this PowerShell script to solve my desire.
This PowerShell script has been a game-changer, allowing me to switch between light and dark modes effortlessly and enhancing my overall user experience.
win11darklightmode.ps1
<#
.SYNOPSIS
A PowerShell script to switch between light and dark mode in Windows.
.DESCRIPTION
This script allows the user to switch between light and dark mode in Windows by setting the DarkMode parameter to 0 or 1 respectively. If executed without parameters, it will toggle between light and dark mode.
.PARAMETER DarkMode
An integer parameter that controls the dark mode setting. The default value is -1. Set to 0 to enable light mode and 1 to enable dark mode.
.EXAMPLE
.\win11darklightmode.ps1 -DarkMode 0
Enables light mode in Windows.
.EXAMPLE
.\win11darklightmode.ps1 -DarkMode 1
Enables dark mode in Windows.
.EXAMPLE - Direct execution via Explorer right click
.\win11darklightmode.ps1
The function automatically checks if Windows 11 is currently in Dark Mode and switches to Light Mode accordingly. It also verifies if Windows 11 is in Dark Mode and then switches to Light Mode.
#>
[CmdletBinding()]
param(
[int]$DarkMode = -1
)
if ($DarkMode -eq -1) {
# Toggle between light and dark mode if executed without parameters
$currentTheme = Get-ItemPropertyValue `
-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
-Name AppsUseLightTheme
if ($currentTheme -eq 1) {
$DarkMode = 1
} else {
$DarkMode = 0
}
}
switch ($DarkMode) {
0 {
# Handle DarkMode = 0 case
Write-Output "Light mode is enabling..."
Set-ItemProperty `
-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
-Name AppsUseLightTheme `
-Value 1
Set-ItemProperty `
-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
-Name SystemUsesLightTheme `
-Value 1
Write-Output "Please wait while Windows Explorer restarts..."
Stop-Process -Name explorer
}
1 {
# Handle DarkMode = 1 case
Write-Output "Dark mode is enabling..."
Set-ItemProperty `
-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
-Name AppsUseLightTheme `
-Value 0
Set-ItemProperty `
-Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
-Name SystemUsesLightTheme `
-Value 0
Write-Output "Please wait while Windows Explorer restarts..."
Stop-Process -Name explorer
}
default {
# Handle any other cases (the message below will not be shown since simple execution with auto swtich for dark to light and vice versa)
Write-Warning "If you do not provide a parameter - it will auto switch from Dark to Light and vice versa"
Write-Output "-DarkMode 0 - Change Windows Theme to Light mode"
Write-Output "-Darkmode 1 - Change Windows Theme to Dark mode"
}
}
# Get the command name
$CommandName = $PSCmdlet.MyInvocation.InvocationName;
# Get the list of parameters for the command
# $ParameterList = (Get-Command -Name $CommandName).Parameters;
How to automatically schedule light mode and dark mode
My next blog post will show you how to do schedule your computer to automatically turn on and off dark mode.
https://huetruong.com/automatically-switch-to-dark-mode-in-windows-11/
Link to my Github repository below ⬇️
https://github.com/huetruong/Win11DarkLightMode