knowing that is possible in PS, exporting SPList items to PS objects(link1 link2) what is the best way, to go into the other way: Create/Update an SPList from an exported csv or format-table.
3 Answers
After creating manually an list based on or csv template via UI...
#get data
$csv = Import-Csv ‘C:\MyData.csv‘
#get list
$web = Get-SPWeb -identity “MyTargetListURL”
foreach ($row in $csv) {
#Check for existing item
$SPItem = $SPList.Items | Where { $_["ItemId"] -eq $row.ItemId }
If ($SPItem -ne $null) {
$SPItem["ColumnNumberType"] = [System.Convert]::ToInt32($row.ColumnNumberType)
$SPItem["Column with special-chars"] = $row."Column with special-chars"
#rest of fields
$SPItem.Update()
}
Else {
$SPNewItem = $SPList.Items.Add()
$SPNewItem["ItemId"] = $row.ItemId
#rest of fields
$SPNewItem.Update()
}
}
There are 3rd party tools that can automate the update process (only changed items updated, so you can add workflows or attachments).
See here for step-by-step guide: http://www.layer2.de/en/community/FAQs/BDLC/Pages/How-to-connect-text-file-to-sharepoint-list.aspx
-
Thanks a lot for the reply, but actually is not a complex PS script to do that. I just wanna know the best way to go.– falloutCommented Jun 29, 2012 at 7:37
I think fallout's answer partially answers the question. His 'if statement' checks if items exist, then updates items if they exist, otherwise it creates new items if they do not exist. Depending on your columns, the trick is to update only those items that have changed in the CSV file (required for efficient version control in the sharepoint list).