Created
January 30, 2018 16:42
-
-
Save michaellwest/2c16946aed8653ec2694c24decf4ed1f to your computer and use it in GitHub Desktop.
Search all fields for a keyword using Sitecore PowerShell Extensions.
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
<# | |
.SYNOPSIS | |
Find all of the items and fields which contain a specific text. | |
.LINK | |
https://vandsh.github.io/sitecore/2018/01/27/spe-search-replace.html | |
#> | |
$rootItem = Get-Item -Path "master:/sitecore/content/Home" | |
$needle = "nurse" | |
@($rootItem) + @($rootItem.Axes.GetDescendants() | Initialize-Item) | | |
ForEach-Object { | |
$currentItem = $_ | |
Get-ItemField -Item $currentItem -ReturnType Field -Name "*" ` | |
| ForEach-Object{ | |
if($PSItem.Value.Contains($needle)){ | |
[pscustomobject]@{ | |
"Name"=$currentItem.DisplayName | |
"ItemId"=$currentItem.ID | |
"FieldName"=$_.Name | |
"ItemPath" = $currentItem.Paths.Path | |
} | |
} | |
} | |
} | Show-ListView | |
$criteria = @( | |
@{Filter = "DescendantOf"; Value = $rootItem.ID }, | |
@{Filter = "Contains"; Field = "sxacontent"; Value = "nurse"} | |
) | |
Find-Item -Index sitecore_master_index -Criteria $criteria | Initialize-Item | | |
Show-ListView -Property @{"Label"="DisplayName";Expression={$_.DisplayName}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment