Search Results for

    Show / Hide Table of Contents

    Add-SearchRule

    Adds search rules to a search catalog.

    Syntax

    Add-SearchRule
       [-Path] <String[]>
       [-RuleType] <SearchRuleType>
       [[-RuleSet] <SearchRuleSet>]
       [-OverrideChildren]
       [-Catalog <String>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
    
    Add-SearchRule
       -InputObject <SearchRuleInfo[]>
       [-OverrideChildren]
       [-Catalog <String>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
    

    Description

    The Add-SearchRule cmdlet adds search rules to a search catalog.

    Examples

    Example 1: Add search rules

    Add-SearchRule -Path file:///C:\Users\Bob\Documents\FooData\ -RuleType Exclude -RuleSet User
    Add-SearchRule -Path file:///C:\Users\Bob\Documents\FooData\Common\ -RuleType Include -RuleSet User
    

    The first command adds a user exclusion rule to the default Windows Search catalog. The FooData directory and all its subdirectories are excluded from the catalog.

    The second command amends the exclusion by making an exception for one subdirectory. The subdirectory Common is included in the catalog, all other subdirectories of FooData are still excluded.

    If the specified path is recognizable as a file system path, you can omit the file:/// protocol prefix.

    Example 2: Override child rules

    Add-SearchRule -Path file:///C:\Users\Bob\Documents\FooData\ -RuleType Exclude -RuleSet User -OverrideChildren
    

    This command adds a user exclusion rule to the default Windows Search catalog. The FooData directory and all its subdirectories are excluded from the catalog, any existing child rules are removed.

    Without the OverrideChildren parameter, child rules, like the one for the subdirectory Common in Example 1, would remain active.

    Example 3: Use wildcards in exclusion rules

    Add-SearchRule -Path file:///C:\Users\*\Documents\PowerShell\ -RuleType Exclude -RuleSet Default
    

    This command adds a default exclusion rule to the default Windows Search catalog. The PowerShell subdirectory in the Documents directory of every user is excluded from the catalog.

    Parameters

    -Catalog

    Specifies the name of the catalog this cmdlet operates on. If omitted, this is the default Windows Search catalog, named SystemIndex.

    Type

    string

    Position

    Named

    Default value

    SystemIndex

    Accept pipeline input

    False

    Accept wildcard characters

    False

    -InputObject

    Specifies SearchRuleInfo objects containing search rules with their properties to be added to a search catalog.

    Type

    SearchRuleInfo[]

    Position

    Named

    Default value

    None

    Accept pipeline input

    True (ByValue)

    Accept wildcard characters

    False

    -OverrideChildren

    Use this parameter to remove any child rules when adding a user search rule.

    Type

    SwitchParameter

    Position

    Named

    Default value

    None

    Accept pipeline input

    False

    Accept wildcard characters

    False

    -Path

    Specifies the URL or path of the search rule to be added to a search catalog. For exclusion rules, the path can contain the wildcard character *.

    Type

    string[]

    Position

    0

    Default value

    None

    Accept pipeline input

    True (ByValue)

    Accept wildcard characters

    False

    -RuleSet

    Specifies the rule set the rule belongs to. The acceptable values for this parameter are:

    • User - Adds a user rule to the working rule set.
    • Default - Adds a default rule to both the working rule set and the default rule set.

    Type

    SearchRuleInfo.SearchRuleSet

    Accepted values

    User, Default

    Position

    2

    Default value

    User

    Accept pipeline input

    False

    Accept wildcard characters

    False

    -RuleType

    Specifies the type of the rule. The acceptable values for this parameter are:

    • Exclude - The rule specifies an exclusion.
    • Include - The rule specifies an inclusion.

    Type

    SearchRuleInfo.SearchRuleType

    Accepted values

    Exclude, Include

    Position

    1

    Default value

    None

    Accept pipeline input

    False

    Accept wildcard characters

    False

    Inputs

    string[]

    You can pipe paths to this cmdlet.

    SearchRuleInfo[]

    You can pipe SearchRuleInfo objects to this cmdlet.

    Outputs

    None

    This cmdlet returns no output.

    Notes

    To learn more about search rules, see Managing Scope Rules in Microsoft's Windows Search documentation.

    Related Links

    • Get-SearchRule

    • Remove-SearchRule

    • Reset-SearchRule

    • Test-SearchRule

    In this article
    Back to top Copyright © 2023 Matthias Wolf, Mawosoft