Sitecore PowerShell script to list unused media items with a prompt for folder location

I was recently asked to produce a report of all the unused media items in Sitecore for a specific Region folder and if you have the PowerShell extensions installed then there is a great one in there called “Media items not used by content items”.

Unfortunately this takes a very long time to run if you have a huge amount of media items in your library and didn’t allow the end user to specify a folder which lead me to extend it a little bit.

By extending the original script by Michael West and adding a Read-Variable prompt it gives the end user more flexibility:

$result = Read-Variable -Parameters `
 @{ Name = "item"; Title="Analyse subitems of"; Tooltip="Folder you want to analyse."; Root="/sitecore/media library/"} `
 -Title "Find all media items that are not in use" -Width 600 -Height 200 `
 -OkButtonName "Proceed" -CancelButtonName "Abort"

Which displays like so:

sitecore powershell read item prompt

You then get a brilliant list view of the results once the script has finished which allows the end user to export as CSV, Excel etc

sitecore powershell script dialog report list

The full script can be found here: https://gist.github.com/RyanDurkin/992aaff199b706a3a7920d956055f529

Sitecore PowerShell script to list unused media items with a prompt for folder location