-2

I'm writing a Sitecore PowerShell script to get all images (without their Media Folders) under the path master:\sitecore\media library, where the Media attached is empty.

I am using the below code but its not working:

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

$items | ForEach-Object {
   Write-Host "Item name: " $_.Name  $_.Paths.FullPath
}
6
  • And what's the question? – Marek Musielak Nov 24 '20 at 7:34
  • basically its not working – Akshay Nov 24 '20 at 7:36
  • [yourItem]._Fields["Media"] is a Field not a string – Mark Cassidy Nov 24 '20 at 7:53
  • so, what needs to be written here – Akshay Nov 24 '20 at 7:54
  • try to use $_.Fields["Media"].value – Mahendra Shekhawat Nov 24 '20 at 8:11
2

There is already a post by Michael west to find the blob value from the image. Just try to reuse it. https://gist.github.com/michaellwest/edf8154f8fb4b8d2636390ba76707a48

$path = "/sitecore/media library/Project/Hackathon/Sitecore Hackathon"
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.TemplateID -ne
[Sitecore.TemplateIDs]::MediaFolder }
$items | ForEach-Object {
  $mediaItem = [Sitecore.Data.Items.MediaItem]$_
  $blobField = $mediaItem.InnerItem.Fields["blob"]
  if([string]::IsNullOrEmpty($blobField))
  {
      Write-Host "Empty Blob Item : "  $_.Name  $_.Paths.FullPath
  }
}

Just a suggestion. Please ask such type of questions in Slack channel #SPE.

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.