Sitecore PowerShell has a way to retrieve a media item from media library. Send-File. You pass the ID or the path of media item and file will be downloaded using Send-File command.
PS master:\> Get-Item "master:/media library/Logo/Blog" | Send-File -Message "Blog"
In order to download all the media items from a folder, SPE has a script out of the box in the context menu. Select the folder --> Scripts --> Download. This will download all the media items, zip it and download it. Please note that the space in the file name will be replace with %20.
We had a requirement where we need to download a list of media items from various folders. We had the list of media item path and ID in a CSV. If we loop through each ID and trigger Send-File, PowerShell should prompt a window for each file to download the file. Since we had more than 300+ items, clicking download button on each prompt is not a good solution. We used -NoDialog parameter to skip the prompt but Sitecore hangs after the first media download. As per this article, if we pass on the -NoDialog, Sitecore hangs for some reason.
So we went through the Download script (/sitecore/system/Modules/PowerShell/Script Library/SPE/Maintenance/Media Library Maintenance/Content Editor/Context Menu/Download) which is provided out of the box. We modified to send the list of items to be downloaded via CSV.
Our CSV had one column with ID as header. Listed all the media items IDs to be downloaded. Below script will retrieve each items based on CSV, zip it using OOTB script and download it.
No comments:
Post a Comment