Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Hiding TaskBar Search with PowerShell

Posted on May 21, 2021May 21, 2021

Yesterday I shared a few PowerShell functions for configuring the Windows 10 taskbar to auto-hide. This works great in my virtual desktop when recording my Pluralsight courses. But even when hidden I would still get an annoying white sliver from the search box. So I got rid of that as well. Here are some PowerShell functions that will hide and unhide the Search box in a Windows 10 desktop. Yes, there are manual steps to hide this feature, but I'm automating here! As always, even if you don't think you need to do this, there might be useful PowerShell nuggets in the code.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The setting that controls the search box is in the registry for the current user. The registry setting is HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search. Underneath that a key called SearchBoxTaskbarMode controls the display. More than likely this key doesn't exist on your desktop. If the DWord value is 0, the search box will be hidden. A value of 2 will display it. You can use PowerShell to set this value.

Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force

The -Force parameter will create the entry if it doesn't exist. As with auto-hiding the taskbar, you will need to restart the Explorer process. Since I'm doing this often it seems, I decided to put this into a separate function. One reason is that when using the Windows Sandbox, sometimes Explorer doesn't automatically restart as it should. My function kills Explorer, tests if it is running and if it isn't starts it.

Function Restart-Explorer {
    <#
    .Synopsis
    Restart the Windows Explorer process.
    #>
    [cmdletbinding(SupportsShouldProcess)]
    [Outputtype("None")]
    Param()

    Write-Verbose "[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)"
    Write-Verbose "[$((Get-Date).TimeofDay) BEGIN  ] Stopping Explorer.exe process"
    Get-Process -Name Explorer | Stop-Process -Force
    #give the process time to start
    Start-Sleep -Seconds 2
    Try {
        Write-Verbose "[$((Get-Date).TimeofDay) BEGIN  ] Verifying Explorer restarted"
        $p = Get-Process -Name Explorer -ErrorAction stop
    }
    Catch {
        Write-Warning "Manually restarting Explorer"
        Try {
            Start-Process explorer.exe
        }
        Catch {
            #this should never be called
            Throw $_
        }
    }
    Write-Verbose "[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)"
}

I then built relatively simple functions to disable and enable the search box.

Function Disable-TaskBarSearch {
    <#
    .Synopsis
     Disable the Windows taskbar search box
    #>
    [cmdletbinding(SupportsShouldProcess)]
    [Alias("Hide-SearchBar")]
    [OutputType("Boolean")]
    Param()

    Begin {
        Write-Verbose "[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)"
    } #begin
    Process {
        Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Hiding Task Bar Search"

        Try {
            $splat = @{
                Path        = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search'
                Name        = 'SearchBoxTaskbarMode'
                Value       = 0
                Type        = 'DWord'
                Force       = $True
                ErrorAction = 'Stop'
            }
            Set-ItemProperty @splat
            if ($WhatIfPreference) {
                #return false if using -Whatif
                $False
            }
            else {
                $True
            }
        }
        Catch {
            $False
            Throw $_
        }
        Restart-Explorer
    } #process
    End {
        Write-Verbose "[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)"
    } #end
}

Function Enable-TaskBarSearch {
    <#
    .Synopsis
     Enable the Windows taskbar search box
    #>
    [cmdletbinding(SupportsShouldProcess)]
    [Alias("Show-SearchBar")]
    [OutputType("Boolean")]
    Param()

    Begin {
        Write-Verbose "[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)"
    } #begin
    Process {
        Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Showing Task Bar Search"

        Try {
            $splat = @{
                Path        = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search'
                Name        = 'SearchBoxTaskbarMode'
                Value       = 2
                Type        = 'DWord'
                Force       = $True
                ErrorAction = 'Stop'
            }
            Set-ItemProperty @splat
            if ($WhatIfPreference) {
                #return false if using -Whatif
                $False
            }
            else {
                $True
            }
        }
        Catch {
            $False
            Throw $_
        }

        Restart-Explorer
    } #process
    End {
        Write-Verbose "[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)"
    } #end
}

You can see that the functions call the Restart-Explorer function. My version of SearchBarTools.ps1 includes that function. I also decided to have the function write a boolean result to the pipeline. I can use this in control scripts if I want to verify the process.

These commands also support -WhatIf which will be passed on to the Restart-Explorer function.

Now I have a set of PowerShell tools that I can use with my desktop automation tools to configure settings exactly as I need them for my coursework.

Hope you found something useful in the code. Enjoy.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “Hiding TaskBar Search with PowerShell”

  1. Pingback: ICYMI: PowerShell Week of 28-May-2021 – PowerShell.org
  2. Fred Jacobowitz says:
    June 2, 2021 at 7:58 am

    Nice one. Now I am ready to dive into the world of [cmdletbinding(SupportsShouldProcess)].

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d