5

I want to know is there any way to create new items in sitecore using the powershell with data from excel sheet

3 Answers 3

8

Should be fairly simple. You can use the PowerShell Import-CSV command to load a CSV file in:

$importRows = Import-CSV "C:\path-to-your-file\import-data.csv"

Then you can enumerate through that and create the items using the New-Item command. This example assumes a field name in the CSV of ItemName. For speed you probably want to wrap this in a BulkUpdateContext

New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext)
{
    foreach ($row in $importRows)
    {
        $itemName = $row.ItemName
        $newItem = New-Item -Path "master:\content\parent-item" -Name $itemName -ItemType <Set the template path & name>
        # Now you can edit the $newItem and set some field values too
    }
}

That should get you started.

0
0

Follow these steps.

  1. Go to admin site by accessing this link "myproducts/sitecore" site using proper credentials
  2. Create a template e.g. products with columns you mentioned -Product Name -Product Title - Product Description enter image description here

  3. Now configure powershell in your sitecore instance if not done already. See below link.

https://marketplace.sitecore.net/en/Modules/Sitecore_PowerShell_console.aspx

Running PowerShell scripts without using Sitecore PowerShell Extensions module

  1. Once installed properly Go to powershell from sitecore admin site

  2. Follow instruction given above by Richard.

    $row in Richard's solution above will give you access to entire row at a time.

  3. Create items based on templates you created under designated path of your content tree

0

Find the PowerShell Code below:

#Define path you want to create sitecore Items
$parentPath ="master:/sitecore/content/Helixbase/Models"
#Read CSV file
$importList = Import-CSV "C:\CSVFile\SampleCSVImport.csv"
foreach ( $row in $importList ) {
    $name = $row.Title
    #Check if Title is not empty
    if($name.Trim() -eq "")
    {
        write-host "Item name should not be blank: " $name  
        continue
    }
    $itemPath = $parentPath + "/" + $name #Create Item path
    $currentItem = Get-Item -Path $itemPath -ErrorAction SilentlyContinue #Get the sitecore Item
    if($currentItem -eq $null) #Check if Item is null then create new Item
    {
        try
        {
            $item = New-Item -Path $itemPath -ItemType "/sitecore/templates/Project/Helixbase/Page Types/Sample Page"                                
            write-host "Item created: " $itemPath             
        }             
        catch
        {
            write-host "Failed to create Item: " $itemPath                
            write-host $_.Exception.Message    
            continue
        }
    }
    #Assign Field values to the Sitecore Item  
    $item.Editing.BeginEdit()
    $item["Title"] = $row.Title
    $item["Description"] = $row.Description
    $item["Summary"] = $row.Summary
    $item.Editing.EndEdit()
}

for more details refer to Blog Post: Import CSV Data in Sitecore Using PowerShell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.