I have Sitecore 8.2 where I got spe version 6.4
I have got a csv file, where sample of data i.e. one row looks as
"Item ID","Title","Created","Changed","Media-ID","Related Site","Search Tags"
"{565E7592-8CA7-46D9-8399-2AB5E66C4EEB}","opening hours","4/17/2018 5:52:40 AM","4/23/2018 3:37:07 AM","{8BC6415F-DCB8-491B-BA3F-CD4FCF27CFD9}","Council", "About us"
Now, I want to download the media item used by this item whose item ID is in this sample data, {8BC6415F-DCB8-491B-BA3F-CD4FCF27CFD9}
is a media item id used in this item, and the media is in /sitecore/media library
path
so for this I have written script which is trying to read from csv file(where these above sample data are), then find 'Media-ID' column for each row and find the item in the given path based on the media item id
I am trying to download the media item using Send-File
, and my script looks like
# Read the CSV file
$csvData = Import-Csv -Path "C:\Usman\news_export.csv"
# Loop through each row in the CSV data
foreach ($row in $csvData) {
$mediaId = $row.'Media-ID'
# Check if Media-ID is not empty
if (-not [string]::IsNullOrEmpty($mediaId)) {
$mediaItemPath = "master:/sitecore/media library"
Write-Host "Media ID: $mediaId"
Write-Host "Media Item Path: $mediaItemPath"
# Get the media item
$mediaItem = Get-Item -Path $mediaItemPath -ID $mediaId
# Check if media item exists
if ($mediaItem -ne $null) {
# Download the media item
Send-File -Item $mediaItem -Message "Download"
} else {
Write-Host "Media item with ID '$mediaId' not found."
}
}
}
My questions
- How do I make this work/any other way to achieve this?
- How do I specify a path to download, like if I need to download in
C:\myImage\imageFolder
,how do I do that?
Thanks :)
Update:
Thanks Everyone, I am actually trying to read from
$csvData = Import-Csv -Path "C:\Usman\news_export.csv"
and grab data from this csv from each row's "Media-ID" column. Then search on media library(based on media library path '\sitecore\media library
') and search for that media item id. Which I have grabbed from csv already in above script.
The main thing is it does download but shows 0 kb
with my code.
how do I create a zip package adding all these media items, and then download this zip specifying the path where is this zip to be downloaded