Posts

Showing posts from October, 2023

PowerShell Script to remove unused media items from Sitecore CMS

Image
Upon receiving a client requirement to identify and eliminate unused media items from the CMS, we crafted the following PowerShell script. This script was developed by referencing various Sitecore-related blogs and posts on the Sitecore Stack Exchange community portal. Its purpose is to efficiently remove unused media items while maintaining logs of the items removed. It's crucial to highlight that before executing this script, it is strongly recommended to take a backup of the master database for precautionary measures. $timenow = [ datetime ]:: Now $IsoDateNow = [ sitecore.dateutil ]:: ToIsoDate ( $timenow ) $IsoDateToUtcIsoDate = [ sitecore.dateutil ]:: IsoDateToUtcIsoDate ( $IsoDateNow ) $sitePath = "D:\inetpub\wwwroot\DirectAxis10\Website\App_Data" $logItem = new-object PSObject | select-object ID, MediaPath, Status, UsedByItemPath $logFilepath = $sitecorelogFolder + "\Media-Delete_" + $IsoDateToUtcIsoDate + ".csv" remove-item $logFile...