3

I'm writing a Sitecore PowerShell script to get all images (without their Media Folders) under the path master:\sitecore\media library, where the File Path in the Media section is empty, like the following image

enter image description here

This is my code

$path = "master:\sitecore\media library"
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder }

$items | ForEach-Object {
   Write-Host "Item name: " $_.Name  
}

I need to add another condition to get all images with empty file path but I don't know how to do it, I'm a newbie with Sitecore.

I use Sitecore 8.2

1 Answer 1

6

You just need to add a filter for filepath empty: ([string]::IsNullOrEmpty($_.Fields["File Path"])) The final query will be:

$path = "master:\sitecore\media library"
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder -and ([string]::IsNullOrEmpty($_.Fields["File Path"]))}

$items | ForEach-Object {
   Write-Host "Item name: " $_.Name  $_.Paths.FullPath
}
1

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.