Test-Rule
Tests item against a sitecore serialized rules engine rule set.

Syntax

Test-Rule [-Rule <String>] [-InputObject <PSObject>] [-RuleDatabase <String>]

Detailed Description

Tests item or a stream of items against a sitecore serialized rules engine rule set.
© 2010-2019 Adam Najmanowicz, Michael West. All rights reserved. Sitecore PowerShell Extensions

Parameters

-Rule <String>

Serialized sitecore rules engine rule. Such rules can be read from rule fields or created by user with the Read-Variable cmdlet.
Aliases
Text
Required?
false
Position?
named
Default Value
​
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-InputObject <PSObject>

Item to be tested
Aliases
Text
Required?
false
Position?
named
Default Value
​
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-RuleDatabase <String>

Name of the database from which rules are pulled.
Aliases
Text
Required?
false
Position?
named
Default Value
​
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.
  • Sitecore.Data.Items.Item

Outputs

The output type is the type of the objects that the cmdlet emits.
  • System.Boolea

Notes

Help Author: Adam Najmanowicz, Michael West

Examples

EXAMPLE 1

Specifies a rule as "items that have layout" and runs the rule againste all items under the ome Item
1
$rule = '<ruleset>
2
<rule uid="{9CF02118-F189-49C4-9F2B-6698D64ACF23}">
3
<conditions>
4
<condition id="{A45DBBAE-F74F-4EFE-BBD5-24395E0AF945}" uid="ED10990E15EB4E1E8FCFD33F441588A1" />
5
</conditions>
6
</rule>
7
</ruleset>'
8
​
9
Get-ChildItem master:\content\Home -Recurse | ? { Test-Rule -InputObject $_ -Rule $rule -RuleDatabase master}
Copied!

EXAMPLE 2

Asks user for the rule and root under which items should be filtered, and lists all items fulfilling the rule under the selected path
1
$rule = '<ruleset></ruleset>'
2
$root = Get-Item master:\content\home\
3
​
4
$result = Read-Variable -Parameters `
5
@{Name="root"; title="Items under"; Tooltip="Items under the selected item will be considered for evaluation"}, `
6
@{Name="rule"; Editor="rule"; title="Filter rules"; Tooltip="Only items conforming to this rule will be displayed."} `
7
-Description "This dialog shows editor how a rule can be taken from an item and edited using the Read-Variable cmdlet." `
8
-Title "Sample rule editing" -Width 600 -Height 600 -ShowHints
9
​
10
if($result -eq "cancel"){
11
exit;
12
}
13
​
14
Get-ChildItem $root.ProviderPath | ? { Test-Rule -InputObject $_ -Rule $rule -RuleDatabase master}
Copied!

Related Topics