powershell - Sitecore PowerShell 在脚本中快速搜索

标签 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 {
}

因为数据很大,我花了大约 1 分钟来获取所有项目。

所以我尝试使用 Find-Item 来加快搜索过程

Find-Item -Index 'sitecore_mastre_index' -Where 'TemplateName = @0' -WhereValues 'myTemplate'

它给了我以下警告,请注意我使用的是 Sitecore 7.2 版

WARNING: The parameter Where is not supported on this version of Sitecore due to platform limitations.

This parameter is supported starting from Sitecore Version 7.5

有没有一种方法可以比使用 Get-ChildItem 更快地使用 PowerShell 检索数据?

注意:如果我使用 Get-Item .,查询仅返回前 100 个项目。我还有很多东西。

最佳答案

有几件事需要考虑。

示例: Get-ChildItem

# 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

示例:查找项目

# 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

示例:快速查询的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

我们整理的这本书也可能对您有所帮助。 https://www.gitbook.com/book/sitecorepowershell/sitecore-powershell-extensions/details

关于powershell - Sitecore PowerShell 在脚本中快速搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34493108/

相关文章:

Sitecore Droptree 不会排除项目

kubernetes - Sitecore 10 K8S 部署 - 无效的 redirect_uri 和 key 集缺失错误

powershell - 在 Azure 中运行 powershell 脚本

如果未找到进程名称,则 Powershell 将进程名称放入哈希表时出现问题

windows - 如何在Powershell中检查端口是否打开

membership - Sitecore 自定义用户配置文件 - 它存储在哪里,如何查询

javascript - 从 PowerShell 打开 Internet Explorer 时出现问题

powershell - 在 Azure VMRole 上公开端口

ASP.NET 5 和 Sitecore 8

model-view-controller - Sitecore MVC 多步骤表单