Last active
March 20, 2020 15:10
-
-
Save tackme31/9d9ba09f67f97fbeec885a7e0c50c55e to your computer and use it in GitHub Desktop.
A Sitecore PowerShell Extensions script for searching items with non-default value in the field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$readVariableParams = @{ | |
Parameters = @( | |
@{Name="root"; Title="Root item"; Editor="droptree"; } | |
@{Name="template"; Title="Template"; Editor="droptree"; Source="DataSource=/sitecore/templates" } | |
@{Name="fieldname"; Title="Field name" } | |
) | |
Title = "Search Edited Items" | |
Description = "Search items with non-default value in the field." | |
} | |
$result = Read-Variable @readVariableParams | |
if ($result -ne "ok") { | |
exit | |
} | |
if ($root -eq $null) { | |
Show-Alert "Root item is required." | |
exit | |
} | |
if ($template -eq $null) { | |
Show-Alert "Template is required." | |
exit | |
} | |
if ([string]::IsNullOrEmpty($fieldname)) { | |
Show-Alert "Field name is required." | |
exit | |
} | |
if (-not $template.DescendsFrom([Sitecore.TemplateIDs]::Template)) { | |
Show-Alert "'$($template.Name)' is not a template." | |
exit | |
} | |
$items = Get-ChildItem "$($root.Database.Name):$($root.Paths.Path)" -Recurse ` | |
| where { $_.DescendsFrom($template.ID) } ` | |
| where { -not $_.Fields[$fieldname].ContainsStandardValue } | |
$fieldNameProp = @{ | |
Name = $fieldname | |
Expression = { | |
$escaped = [System.Net.WebUtility]::HtmlEncode($_[$fieldname]) | |
return ($escaped -replace "\n","<br>" -replace " "," ") | |
} | |
} | |
$items | select Icon,Name,ItemPath,$fieldNameProp | Show-ListView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment