Hi
I'm trying to create new items based on a CSV - I found some examples with CSOM but I have some errors and I cannot upload this items.
this is the code
$csv = Import-CSV mycsv.csv $siteUrl = "https://mytenant.sharepoint.com" $listName = "mylist" $userName = "my@tenant.email.address" $password = Read-Host -Prompt "Enter password" -AsSecureString $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password) $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $context.Credentials = $credentials [Microsoft.SharePoint.Client.Web]$web = $context.Web [Microsoft.SharePoint.Client.List]$list = $web.Lists.GetByTitle($listName) $intIndex = 0; $addGroup = 0; write-host "`nImporting data..." foreach ($row in $csv) { [Microsoft.SharePoint.Client.ListItemCreationInformation]$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation; [Microsoft.SharePoint.Client.ListItem]$item = $list.AddItem($itemCreateInfo); #Customer,StartDate,DueDate,SupportType,AssignedTo,TaskStatus,Title $item["Title"] = $row.Title; $item["Customer"] = $row.Customer; $item["Description"] = $row.TaskStatus; $item["AssignedTo"] = $row.AssignedTo; $item["Support_x0020_Type"] = $row.SupportType; $item["Start_x0020_Date"] = [Datetime]::parse($row.StartDate); $item["Due_x0020_Date"] = [Datetime]::parse($row.DueDate); $item.Update(); $addGroup++ if($addGroup -eq 20) { $context.ExecuteQuery(); $addGroup = 0; } write-host "`r".padleft(40," ") -nonewline write-host "Count : $intIndex $row.Title" -nonewline $intIndex++ } Write-Host "Import completed".
When I Ran this, i get the following error:
Exception calling "ExecuteQuery" with "0" argument(s): "Invalid data has been used to update the list item. The field you are trying to update may be read only." At C:\scripts\importtable.ps1:61 char:9+ $context.ExecuteQuery();+ ~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ServerExceptionAfter "binging" a lot I suppose there is a problem with lookup field and... i think... with person field (Customer and AssignedTo fields) but I can't find examples that I can understand (the last sentence I wrote was LOAD $,8,1)
<br/> Saludos<br/> <br/> <b>Rodrigo de los Santos</b><br/> rodrigo.delossantos at mug.org.ar<br/> rodrigo at dlssolutions.net<br/> ------------------------------------------------<br/> <b>MCITP EA - MCSE - MCTS - MCT - FCNSA</b><br/> Miembro del Grupo de Virtualización y System Center (argentina Uruguay)<br/> <a href="http://dls.ms/vm">http://dls.ms/vm</a>)<br/> ------------------------------------------------<br/> Miembro del MUG Argentina (suscribite! <a href="http://www.mug.org.ar">http://www.mug.org.ar</a>)<br/> ------------------------------------------------<br/> Url: <a href="http://www.dlssolutions.net">http://www.dlssolutions.net</a><br/> Blog: <a href="http://www.nerdsupport.com.ar">http://www.nerdsupport.com.ar</a><br/> ------------------------------------------------<br/>