4

I want to delete all images under the folder Images and all sub-folders too.

This is what I did

$path ="master:\sitecore\media library\images"
$items = Get-ChildItem -Path $path -Recurse 
ForEach ($item in $$items) 
{
   $item | Remove-Item 
}

I need to add a condition to delete all items which their names start with "old_".

Thanks

8

Just add Where-Object { $_.Name -like "old_*" } condition:

$path ="master:\sitecore\media library\images"
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.Name -like "old_*" }
ForEach ($item in $items) 
{
   $item | Remove-Item 
}
  • Thank you, It worked. – Ahmed Elshorbagy Sep 3 at 9:45
  • There is an extra $ character in ForEach loop :) – Surya Sep 3 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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