Automatically enable Dark Theme in Settings app on Windows 10

If you are using Windows 10, you will find a Light and Dark theme for Settings app in Colors section under Personalization settings. By default, it uses Light theme as this is more user-friendly.

Read More

  • Yep, Dark is good...

    But why the multiple scripts, just automate it all in one place,
    One script, one scheduled task.
    FYI, those who are not aware, this key does not exist by default,
    hence using the New and Remove cmdlets.

    ### Begin: A small rant though ###
    ###

    First, why do folks keep suggesting using Notepad and o the non-powershell
    capable editors to write PowerShell scripts, when the built-in PowerShell_ISE
    Is a far better and more intelligent tool for this kind of this.

    You , write, test, debug in a single tool. You cannot do this in non PowerShell
    capable editors like Notepad of course, so why go there at all.

    If one does not like the PowerShell _ISE, for whatever reason, then
    VisualStudioCode, should be the next time of choice.

    Both avoids all the separate tool / copy and paste from notepad or whatever
    back into PowerShell craziness to make scripts, functions, and modules.

    Then of course there are the paid for enterprise PowerShell IDE, like Sapien's
    PowerShell Studio and others free ones like Idera's PowerShellPlus, or even
    Visual Studio Community edition with PowerShell add-ons. Yet these might be
    overkill for many IT pros.

    Drop the Notepad stuff, and user VSCode (super notepad for PowerShell and more).
    Or just use the built-In PowerShell_ISE.

    I know, I know, old habits are hard to break. Well, that, and folks will have their preferences.

    ###
    ### End: A small rant ###

    Example - performing all build, edit, test, validate all in Visual Studio Code
    You have an intelligent editor to help you along the way with full IntelliSense,
    debug and test it live before you set you Task Schedule.

    Last point, once tested you can create that task schedule item using PowerShell directly

    $StartTime = Get-Date '18:00:00'
    $Endtime = Get-Date '08:00:00'
    $CurrentTime = Get-Date

    If ($StartTime.TimeOfDay -le $CurrentTime.TimeOfDay `
    -and $Endtime.TimeOfDay -ge $CurrentTime.TimeOfDay)
    {
    # 'Enableing Dark Theme'

    New-ItemProperty `
    -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
    -Name AppsUseLightTheme `
    -Value 0 `
    -Type Dword -Force
    }
    Else
    {
    # 'Enabling Light Theme'

    New-ItemProperty `
    -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize `
    -Name AppsUseLightTheme `
    -Value 1 `
    -Type Dword -Force
    }

    Now, with this one script all you need is the task schedule, set to start daily
    at 1800hrs (6:00 pm)



    # Create a scheuld task
    $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'D:\Scripts\powershelltipsSet-WindowsTheme.ps1'
    $trigger = New-ScheduledTaskTrigger -Daily -At 6pm
    Register-ScheduledTask -Action $action -Trigger $trigger `
    -TaskName 'Set-WindowsTheme' -Description 'Set the Windows desktop theme to dark or light based on time of day' `
    -User "System"

    # Validate task creation
    Get-ScheduledTask -TaskName 'Set-WindowsTheme'

    # Test the task - If between 6pm and 8am, the theme will be set to dark.
    Start-Process -FilePath schtasks '/run /I /TN "Set-WindowsTheme"'