In a Sitecore content tree, I have a list of about 3000 articles. Each article has an author field. The author field is of type droplink. I am trying to write a PowerShell script that gets me a count of articles that each author has written.
#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($_)}
}
It appears that the call to get the articles by the author Id is not returning anything. Therefore $articles.Count
is always returning 0. I tried to to @Author.Value='$item.Id'
but still didn't get any results. Can anyone see anything I could be doing wrong here?
Unless you are testing against a single property you need to wrap the condition in brackets like this:
$articles = Get-Item master: `
-Query "/sitecore/content/mySite/Home/Articles/2017//*[@@templatename='Article' and @Author='$($item.Id)']"