Dua*_*ieh 3 powershell sitecore
我使用 Sitecore PowerShell 扩展模块创建脚本,将关系从一项复制到相关项。
我用来Get-ChildItem
获取与特定字段相关的所有项目
Get-ChildItem -Recurse . | Where-Object {
$_.TemplateName -match $'myTemplate' -and
$_.Fields[$fromfield].Value -ne $null -and
$_.Fields[$fromfield].Value -ne ""
} | ForEach-Object {
}
Run Code Online (Sandbox Code Playgroud)
由于数据很大,我花了大约 1 分钟来获取所有项目。
所以我尝试使用Find-Item
来使搜索过程更快
Find-Item -Index 'sitecore_mastre_index' -Where 'TemplateName = @0' -WhereValues 'myTemplate'
Run Code Online (Sandbox Code Playgroud)
它给了我以下警告,请注意我使用 Sitecore 版本 7.2
警告:由于平台限制,此版本的 Sitecore 不支持参数Where。
从 Sitecore 版本 7.5 开始支持此参数
有没有办法使用 PowerShell 比使用更快地检索数据Get-ChildItem
?
注意:如果我使用 Get-Item .
查询,则仅返回前 100 项。我还有很多物品。
有几件事需要考虑。
示例:获取子项
# Essentially touches all of the items in the database.
# It's one of the most common ways to query the items,
# but should be a narrow path.
Get-ChildItem -Path "master:\" -Recurse
Run Code Online (Sandbox Code Playgroud)
示例:查找项目
# This example is what you need to query the index.
# You can chain together multiple Criteria by making a comma separated list of hashtables.
# Piping to the Initialize-Item command will convert SearchResultItem to Item.
# PS master:\> help Find-Item -Examples
Find-Item -Index sitecore_master_index -Criteria @{Filter = "Equals"; Field = "_templatename"; Value = "Sample Item"} | Initialize-Item
Run Code Online (Sandbox Code Playgroud)
示例:具有快速查询的 Get-Item
# This example takes advantage of the fast query. Substitute for your use case.
$query = "fast:/sitecore//*[@@templatename='Sample Item']"
Get-Item -Path "master:" -Query $query
Run Code Online (Sandbox Code Playgroud)
我们整理的这本书也可能是有益的。 https://www.gitbook.com/book/sitecorepowershell/sitecore-powershell-extensions/details