To get all items that are using a specific template in Sitecore using PowerShell, you can use the Get-ChildItem
cmdlet to retrieve all items in the content tree, and then filter the items by checking if they have a __template field
with the ID of the template.
Here's some example PowerShell code that demonstrates how to do this:
$templateId = "{12345678-1234-1234-1234-123456789012}" # Replace with your template ID
# Get all items in the content tree
$items = Get-ChildItem -Path "master:\content\home" -Recurse
# Filter the items by template
$itemsUsingTemplate = $items | Where-Object { $_.Fields["__template"].ValueTemplateId -eq $templateId -and !([string]::IsNullOrEmpty($_.Fields["SitecoreField"].Value))}
# Output the item paths
$itemsUsingTemplate | ForEach-Object { Write-Host $_.Paths.Path }
In this example, we're getting all items in the content tree starting from the home item, and then filtering them by checking if they have a __template
field with the ID of the template. The filtered items are stored in the $itemsUsingTemplate variable, and then their paths are outputted using the Write-Host cmdlet. You can replace the template ID and the starting path with your own values.
[Updated] Updated because part with condition didn't work.