Automatically enable Dark Theme in Settings app on Windows 10

What would you like to read next?

1 Comment

  1. ### Begin: A small rant though ###
    ###

    First, why do folks keep suggesting using Notepad and o tthe 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 of course, so why go there at all.

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

    Both avoids all the seperate tool and copy and paste from notepad or whatever
    back into PowerShell craziness.

    Then of course there are teh paidf 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.

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

    Example – perfroming 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:SOFTWAREMicrosoftWindowsCurrentVersionThemesPersonalize `
    -Name AppsUseLightTheme `
    -Value 0 `
    -Type Dword -Force
    }
    Else
    {
    # ‘Enabling Light Theme’

    New-ItemProperty `
    -Path HKCU:SOFTWAREMicrosoftWindowsCurrentVersionThemesPersonalize `
    -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:ScriptspowershelltipsSet-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”‘

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap