Skip to content

Instantly share code, notes, and snippets.

@tackme31
Last active March 20, 2020 15:10
Show Gist options
  • Save tackme31/9d9ba09f67f97fbeec885a7e0c50c55e to your computer and use it in GitHub Desktop.
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.
$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 " ","&nbsp;")
}
}
$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