Emlinie
Emlinie

Reputation: 117

Importing csv to SharePoint list with Powershell

I want to import data from a CSV to a SharePoint list, all I'm getting from my script is blank rows. Here is my code:

# CSV path/File name
$contents = Import-Csv ".\Input.csv"

# Web URL
$web = Get-SPWeb -Identity "http://Zaxiyn/" 

# SPList name
$list = $web.Lists["Technical Profile List"] 


# Iterate for each list column

foreach ($row in $csv) {
    $item = $list.Items.Add();
    $item["Computer"] = $row.Computer;
    $item["ItemOrder"] = $row.ItemOrder;
    $item["Category"] = $row.Category;
    $item["ItemName"] = $row.ItemName;
    $item["ItemValue"] = $row.ItemValue;
    $item.Update();
}

Upvotes: 2

Views: 14062

Answers (1)

Shay Levy
Shay Levy

Reputation: 126852

Looks like you're referring to a variable that doesn't exist. The csv file content is saved in $contents and your foreach statement uses $csv, try this:

foreach ($row in $contents) { ... }

Upvotes: 3

Related Questions