1

I am a powershell newbie. I have to write a Sitecore Powershell script where I need to check all the templates for a particular value. But I need to ignore templates inside /sitecore/templates/System/ folder. What is the best way to implement this?

$items = Get-ChildItem $selectedValues.SelectedFolderPath -Recurse

3 Answers 3

3

You can use Where-Object to exclude items in /sitecore/templates/System node like:

Where-Object { ! $_.Paths.FullPath.StartsWith('/sitecore/templates/System') }

So your full code would be

$items = Get-ChildItem $selectedValues.SelectedFolderPath -Recurse | Where-Object { ! $_.Paths.FullPath.StartsWith('/sitecore/templates/System') }
3

You can try the below script:

$items = Get-ChildItem -Path "master:/sitecore/content/home" -Recurse | 
Where-Object { $_.TemplateName -eq 'Your Template Name'}

You can filter at two levels:

  1. At the -Path level where you can minimize the exposure to the particular list
  2. Where-Object where you can either match the TemplateIds/TemplateName with "-eq" or skip items using "-ne"

Note: -Recurse will give you all the items under the -Path specified but if you don't specify this option, you will only get the items that are just under the -Path

2

You can use the below script to check for your values on the templates. It will check if the item path contains /sitecore/templates/System.

$items = Get-ChildItem $selectedValues.SelectedFolderPath -Recurse

foreach($item in $items){

    if($item.Paths.FullPath -inotmatch "/sitecore/templates/System"){
        Write-Host "Processing item $($item.Name) with path $($item.Paths.FullPath)"
        // perform your check here
    }
    else{
        Write-Host "SKIP. It is a system path for item $($item.Name) - $($item.Paths.FullPath)"
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.