Script to Disable or Enable Windows 7 Search Feature (PowerShell)

Introduction

This PowerShell script demo shows how to disable or enable Windows 7 search feature.

Scenarios

This question is asked by users in the TechNet forum. They just want to disable or enable Windows 7 search feature.

Script

Step 1: Click Start, type powershell in the search box on the Start Menu, right-click the Windows PowerShell icon, and then click Run Windows PowerShell as administrator. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.
Step 2: Run the script in Windows PowerShell Console , type the one command : Import-Module <Script Path> at the command prompt.
For example, type Import-Module C:\Scripts\DisableWindowsSearchFeature.psm1
The step is shown in the following figure.
Step 3: You can type the command Get-Help Set-OSCWindowsSearchFeature -Full to display the entire help file for this function, such as the syntax, parameters, or examples.
 
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
If($Disable) 
{ 
    If($PSCmdlet.ShouldProcess("Disabling Search Feature")) 
    { 
        If($FeatureState-match "Enable") 
        { 
            Write-Host "Disabling Search Feature..." 
            Dism /online /Disable-Feature /FeatureName:SearchEngine-Client-Package 
        } 
        If($FeatureState-match "Disable") 
        { 
            Write-Warning"Search Feature is already disabled."  
        } 
    } 
}

Example

Example 1: Type the Set-OSCWindowsSearchFeature -Disable command in the Windows PowerShell Console. This command shows how to disable Windows Search Feature. 
The result is shown below.
  
Example 2: Type the Set-OSCWindowsSearchFeature -Enable command in the Windows PowerShell Console. This command shows how to enable Windows Search Feature.   
 

Prerequisite

Windows PowerShell 2.0
Windows 7

Additional Resources

http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/4e9a4497-cacc-43d3-82f4-c2b082781ab0
http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/697f2c5d-7d27-403b-b88b-679db769113e