Tagged: Sitecore Powershell

Efficiently bulk edit Sitecore content using Sitecore PowerShell Extensions (SPE)

Efficiently-bulk-edit-Sitecore-content-using-Sitecore-PowerShell-Extensions-SPE-Hero

In today’s fast-paced digital world, website content must be constantly updated to stay relevant. Manually modifying content can be time-consuming and error-prone. Sitecore SPE is a powerful tool that allows for efficient modification of content in bulk through find and replace text functionality. In this article, we will explore the steps of using Sitecore SPE to quickly and easily update website content, streamlining the process and saving time.

I encountered a situation where I needed to locate specific text in both images and rich text fields and replace them in large quantities. Essentially, we were transferring media from the Media Library to the Content Hub.

Find Text for Image and RichText Content-Type:

Replace the $contentPath, $guidPattern $mediaPath according to the project. 

The $guidPattern is for images containing GUID format like https://cdn.companyurl.com/-/media/897222F0-3BCF-4651-AAC4-6CBBC227B449.ashx that needs to be manually modified since we don’t know where the item path lives in Content Hub. These items I’m adding these to the $cdnItemWithoutGuid array and the list will be given to Content Authors for manual editing.

The results will yield one or two variations of results, dependent on the content, referred to as

  • Items that contain cdn.companyurl.com with GUIDEfficiently-modify-Sitecore-content-in-mass-with-Sitecore-PowerShell-Extensions-SPE-Find-without-Guid-View
  • Items that contain cdn.companyurl.com without GUIDEfficiently-modify-Sitecore-content-in-mass-with-Sitecore-PowerShell-Extensions-SPE-Find-with-Guid-View

Retrieve the results in CSV, Excel, XML, HTML, and JSON (and also via Email) and analyze them to ensure they are the expected items.

Replace Text for Image and RichText Content-Type:

Replace the $contentPath, $guidPattern, $cdnMediaPath, and $damMediaPath according to the project. 

The results will yield one or two variations of results, dependent on the content, referred to as

  •  Changed Items View
  •  Not changed Items ViewEfficiently-modify-Sitecore-content-in-mass-with-Sitecore-PowerShell-Extensions-SPE-Not-changed-View

Upon completion, review the output. Inspect the Not changed Items View to determine the reason for its unchanged status, it could be due to it being in a workflow stage or any other cause.

Hope this helps. Happy Sitecoring.

Ref

https://michaellwest.blogspot.com/search/label/powershell

https://blog.najmanowicz.com/category/software-development/powershell/

https://sitecorejunkie.com/category/sitecore-powershell-extensions

 
 
1

Migrate Sitecore Media Library Assets to DAM

Migrate Sitecore Media Library Assets to DAM

When we move into composable architecture. We will need to move the media assets to other platforms. Let’s explore methods of exporting Sitecore Media Library assets to Digital Assets Management (DAM) like Content Hub, AEM, etc. It’s a two-step process of exporting from the source and importing to the destination. We will export the entire Media Library to a zip file and also the asset details to a spreadsheet for validation.

Sitecore Media Library Export to file:

I was exploring the Sitecore Modules, but I realized It could be quickly done using PowerShell Extensions. Right-click on the Media Library node, Navigate to Scripts, and click Download. 

Sitecore_Media_Library_PowerShell_Download

The PowerShell script will run for a few mins in my case it ran for 20 minutes for 3GB (depending upon the Media Library size). If you run into timeout issues. Execute at folder levels and finally combine them.

Once the execution is completed it will prompt a pop-up to download the zip file.

P.S: The zip file is temporarily stored in the App_Data folder, but once we download it, it gets deleted.

Sitecore Media Library Export to CSV:

PowerShell extensions script to help export the media library assets file names and path to a spreadsheet.

 

 

Another approach to export the data is to use the content export tool.

https://github.com/estockwell-alpert/ContentExportTool

Import

Now the assets are ready to be imported to DAM

Sitecore Content Hub follow the steps in the following article https://docs.stylelabs.com/contenthub/3.5.x/content/user-documentation/content-user-manual/create/create-upload-content.html

Adobe Experience Manager you could use the bulk import process following the article

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/migration/bulk-import.html

I hope this helps.

Happy Sitecoring!

1

Bulk update fields using SPE

I came across a scenario, where I need to update the email field for all custom forms built with ‘EmailTemplate’. Since it’s going to be a bulk update, decided to do it in SPE(so powerful!)

Here is the script I wrote –

$path = "master:/sitecore/content/external_forms"
$templateName = "EmailTemplate"
$emailAddresses = "test@test.com"
$fieldName = "ToEmail"
$items = Get-ChildItem -Path $path -Recurse | Where-Object { $_.TemplateName -eq $templateName }
foreach($item in $items) {
if($item.Fields[$fieldName] -ne 'null'){
$item.Editing.BeginEdit()
$item.Fields[$fieldName].Value = $emailAddresses
$item.Editing.EndEdit()
Write-Host ($item.Name + ": " + $item.Fields[$fieldName].Value)
}
}

Hope this helps someone. Any questions, please leave a comment.

Happy Sitecoring!

0