I have to create a report via Sitecore Powershell where I have to fetch all items in Approved workflow state that are created/updated in last 30 days. I am getting the data but seems there are inconsistency in data.
I have tried with the script as shown below:-
$workflowStateID = Get-Item -Path master: -ID "{C674D9DF-B5EA-4F3B-8871-F80B2F214F28}"
$referringItems = Get-ItemReferrer -Item $workflowStateID | Where-Object { $_.__Created -gt [datetime]::Now.AddDays(-30) }
#EmptyArray
$listofWorkflowItems = @()
#$listofWorkflowItems
#Skip System Items
Foreach($item in $referringItems) {
$itemPaths = $item.Paths.FullPath
if($item.Paths.FullPath.contains('/sitecore/content/abc-website'))
{
$rendering = $item | Get-Rendering
$addInList = New-Object System.Object
$addInList | Add-Member -type NoteProperty -name ID -Value $item.ID
$addInList | Add-Member -type NoteProperty -name Path -Value $item.FullPath
$addInList | Add-Member -type NoteProperty -name Created -Value $item.Created
if($item.'__Never publish' -eq 1)
{
$addInList | Add-Member -type NoteProperty -name NeverPublished -Value 'True'
}
if($rendering){
$addInList | Add-Member -type NoteProperty -name URL -Value $item.FullPath.Replace("/sitecore/content/abc-website/home","https://abc.com")
}
$listofWorkflowItems += $addInList
}
}
$listofWorkflowItems | Show-ListView
But I am not getting through with if condition for Never publish property of item.
I have gone through with How to find out what's pending to be published where if condition is mentioned for never publish property. But its not working at my end.
Also the date filter is not working as expected. With the below syntax for items created in last 30 days, I am getting items created in 2017 as well.
$referringItems = Get-ItemReferrer -Item $workflowStateID | Where-Object { $_.__Created -gt [datetime]::Now.AddDays(-30) }
Is there something in syntax which I am missing?
Any help/pointer is much appreciated.