Sitecore Powershell search/filter 通过 droplink 字段

Sitecore Powershell search/filter by a droplink field

在 Sitecore 内容树中,我有大约 3000 篇文章的列表。每篇文章都有一个作者字段。作者字段是 droplink 类型。我正在尝试编写一个 PowerShell 脚本,让我计算每位作者所写文章的数量。

#This is where all the Authors lives
cd 'master:/sitecore/content/mysite/Global/Authors Folder'

#Get all the articles that each author has written
function ProcessItem($item) 
{
$articles = Get-Item master: -Query "/sitecore/content/mySite/Home/Articles/2017//*[@@templatename='Article' and @Author='$item.Id']"
$articles.Count
}

#Get a list of authors
$itemsToProcess = Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match "Authors"  }
if($itemsToProcess -ne $null)
{
   $itemsToProcess | foreach {ProcessItem($_)}
}

似乎通过作者 ID 获取文章的调用没有返回任何内容。因此 $articles.Count 总是返回 0。我尝试 @Author.Value='$item.Id' 但仍然没有得到任何结果。谁能看出我在这里做错了什么?

除非您针对单个 属性 进行测试,否则您需要将条件括在括号中,如下所示:

$articles = Get-Item master: `
    -Query "/sitecore/content/mySite/Home/Articles/2017//*[@@templatename='Article' and @Author='$($item.Id)']"