Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created September 23, 2022 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/a2a0189b11d62d64ea76b777c48145b8 to your computer and use it in GitHub Desktop.
Save michaellwest/a2a0189b11d62d64ea76b777c48145b8 to your computer and use it in GitHub Desktop.
Sitecore PowerShell Extensions report to find all script and script library items containing either a ShowRule or EnableRule.
<#
.SYNOPSIS
Report all the PowerShell Script (Library) items which contain a ShowRule or EnableRule
.NOTES
Michael West
#>
$items = Get-ChildItem -Path "master:" -ID "{A3572733-5062-43E9-A447-54698BC1C637}" -Recurse | Where-Object { ($_.ShowRule -and $_.ShowRule -ne "<ruleset />") -or ($_.EnableRule -and $_.EnableRule -ne "<ruleset />") }
function Render-Rule {
param(
[string]$rule
)
$output = New-Object System.Web.UI.HtmlTextWriter (New-Object System.IO.StringWriter)
$renderer = New-Object Sitecore.Shell.Applications.Rules.RulesRenderer ($rule)
$renderer.Render($output)
$output.InnerWriter.ToString()
}
$items | Show-ListView -Property Name, ItemPath, @{Name="ShowRule";Expression={Render-Rule -Rule $_.ShowRule}}, @{Name="EnableRule";Expression={Render-Rule -Rule $_.EnableRule}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment