Import Csv and Create items and update values into fields using Sitecore powershell.

Prem Murmu on 9/29/2021 3:14:16 PM

Sitecore powershell is very useful module of any version of sitecore. We can do basic operation using Sitecore powershell like create items, update items name and fields values.

Today  I will explain about creating bulk items or creating large of items  and update the values on the fields in fews seconds, so this kind of quick operation can be only done by Sitecore powershell.

I will share a sitecore powershell script for it. It is going to do following job in it.

1. Import csv file (right format file)

2. Read all rows of csv file and get values to some powershell variables

3. There will be condtion flags(Skip or Update) to distinguish the type operation to be done.

Skip means: create item, remove or delete items.

Update: Update the values of existing items

4. Here, we create item and update values , so Skip flag will be in condition as well as in csv file first column.

5. Create item with the help of template item.

6. Manipulate the target item using created item and Update values on fields of the items.


May above steps not much clear but when you will dear to look at below powershell code, you will definitely get it. It is quite easy.

Lets I have to create 50 towns items and feed the values like name of town  into Town Name field.

We will prepare a csv file format.(Download Csv Sample Here)

Note:

1. No space Column Name in csv file

2. Name of the column in csv file should exact same in script row variables

Ex:

Column name

CSV file:

Town_Name

in script:

$Town_Name= $row.Town_Name;

CSV file Format

Column Name

1. Update_Check: Skip conditional flag will in all rows.

2.Item_name: Items will be created with this names

3.Item_Path: Items will navigate to path and create item.

4.Town_Name: town name fields values.


So we will write a script like below Sitecore powershell powershell script. 

 


Paste this scrip to Sitecor powershell ise and execute it and select the csv file.


It will start creating items and also show you logs in powershell console.


0 Comments on this post

Comments(0)||Login to Comments


InterServer Web Hosting and VPS
  • see more..