More times than not, I’ll get a request in from a client to import a bunch of blog posts, news articles or other content from another system into Sitecore. Typically, the easiest way I’ve found this to work is by exporting said content into a spreadsheet/CSV, and in fact many systems include built in ways (or plugins) to do this. Take WordPress for example, there exists plugins to automatically take all or a portion of your posts and export the titles, content, tags and the like into an Excel/Google Sheets document.
Sometimes too, a client may just find it easier to write out a bunch of content into a spreadsheet instead of manually creating items in Sitecore; especially if there’s a lot of pages to deal with.
But what do we do with this content, and how do we get it into Sitecore?
The solution is quite easy, actually, and leaves a ton of room for customizations along the way.
Let’s use our WordPress blog post scenario from earlier. Say we had 1000 blog posts to move from WordPress to Sitecore. Consider an exported spreadsheet containing the following information for each post:
- Title
- Body Content
- Tags
- Author
We can make use of both vanilla PowerShell as well as Sitecore Powershell Extensions to make quick work of batch importing this content.
Using PowerShell’s built in Import-Csv functionality, we can individually parse each row (representing a blog post) and pair that with SPE’s item tools to create a new Sitecore item for each post and update the fields with the information from the document.
Firstly, I would recommend converting the exported spreadsheet into a comma-separated values (CSV) document. If you’re unfamiliar with CSVs, they are essentially spreadsheets broken down into their raw text form, using commas to separate each value for each row, utilizing the first line (columns) to match a row’s value to its column.
Then, using your method of choice, host the CSV somewhere that you can access it from Sitecore. I’ll typically place this into the App_Data folder of the instance I’m working on, but it really doesn’t matter; whatever is easiest for you to work with.
Using the Import-Csv function, we can loop through each line of the CSV and extract the blog post information from it. I’m also setting up some generic variables for where to create the posts in Sitecore, which templates to use, etc.
$filePath = "C:\inetpub\wwwroot\website\App_Data\file.csv"
$folder = "master:\content\TENANT\Website\Blog\"
$template = "Template Location\Template"
Import-Csv -Path $filePath -Delimiter "," | Foreach-Object {
...
}
Within the Import-Csv loop, you can then create a new Sitecore item for each row. When looping through the CSV, you can directly access the column headers by name, so I’ll typically take the Title of the blog post and use that as the Sitecore item’s name. I’ll then pass that name to my function to create the item.
$itemName = $_.'Title'
Note that if you haven’t normalized your titles before exporting your CSV, you’ll need to perform some adjustments to make sure you’re not using illegal characters as defined in your Sitecore configurations.
Using the title, I’ll create a new item with that name:
$itemPath = $folder + $itemName
$item = New-Item -Path $itemPath -ItemType $template
Next, you’ll want to populate the fields of your item with the rest of the information from your CSV. Here’s where you can get a bit creative with your import. Depending on how you intend to use the information from the CSV, you may want to stray from the examples below. For instance, you may have an Author item/page for each contributor of your blog. As such, instead of using a Single-Line Text field to display the author, you may want to look up the item for that author and link it using a Droplink field. For the sake of simplicity, we’ll keep it simple here.
We’ll assume that the fields on the template in Sitecore have names that match the columns in the CSV. If yours differ, simply update the field names in the code below.
try {
$item.Editing.BeginEdit()
$item["Title"] = $_.'Title'
$item["Body Content"] = $_.'Body Content'
$item["Tags"] = $_.'Tags'
$item["Author"] = $_.'Author'
$item.Editing.EndEdit()
}
catch {
$item.Editing.CancelEdit()
}
Depending on the complexity of your logic here, and the number of items you’re importing, this process can take some time. However, this is much, much faster than manually creating items in Sitecore. You can also extend this functionality to perform checks to see if duplicate posts exist by checking the item names or content prior to item creation. Again, for simplicity, these sort of things aren’t included in the example scripts, but are pretty easy to add. Take a look at Test-Path for an easy way to check if an item exists without needing to grab the item object directly.
The Code
Putting it all together we get the following:
$filePath = "C:\inetpub\wwwroot\website\App_Data\file.csv"
$folder = "master:\content\TENANT\Website\Blog\"
$template = "Template Location\Template"
Import-Csv -Path $filePath -Delimiter "," | Foreach-Object {
$itemName = $_.'Title'
$itemPath = $folder + $itemName
$item = New-Item -Path $itemPath -ItemType $template
try {
$item.Editing.BeginEdit()
$item["Title"] = $_.'Title'
$item["Body Content"] = $_.'Body Content'
$item["Tags"] = $_.'Tags'
$item["Author"] = $_.'Author'
$item.Editing.EndEdit()
}
catch {
$item.Editing.CancelEdit()
}
Write-Host "Import complete!"
}
This simple script can save hours or even days when it comes to importing content. This script is pretty versatile and can be used for many different types of content within Sitecore. Have fun getting creative and expanding the functionality to suit your needs.
As always, feel free to leave a comment if you have any questions!

Leave a comment