Unable to import data from csv file to existing SharePoint on premise list

Hemanth Reddy S 1 Reputation point
2020-11-02T12:09:30.407+00:00

I have tried powershell to import data but I keep getting the errors like
You cannot call a method on a null valued expression.
Cannot index into a null array

Can anyone help me in this or suggest any other method to do the import like JavaScript

Windows for business | Windows Server | User experience | PowerShell
{count} votes

4 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-11-02T14:45:07.9+00:00

    Without seeing the code you're using nobody can offer advice that's more than just a wild guess.

    0 comments No comments

  2. Anonymous
    2020-11-03T03:55:08.547+00:00

    Hi,

    Please post your current powershell script and the full error message. It helps others understand your problem.

    Best Regards
    Ian

    0 comments No comments

  3. Hemanth Reddy S 1 Reputation point
    2020-11-03T11:36:01.87+00:00

    Hello,

    Please find the script below

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

    $CSVData= Import-CSV -path "mypath"
    $web= Get-SPWeb -identity "https://mysite"
    $list= $web.Lists["listname"]

    foreach ($row in $CSVData)
    {
    $item= $list.Items.Add();
    $item["Title"]= $row.Title
    $item.Update()

    }

    Error message-
    Cannot index into a null array.
    $list= $web.Lists["listname"]

    You cannot call a method on a null-valued expression.
    $item= $lists.Item.Add();

    Cannot index into a null array.
    $item["Title"] = $row.Title

    You cannot call a method on a null-valued expression.
    $item.Update()

    0 comments No comments

  4. Anonymous
    2020-11-04T04:42:38.19+00:00

    Hi,

    You see all these error messages because $web is null. Please check the result returned by Get-SPWeb. Also according to the help document, to store the results of Get-SPWeb in a local variable, the Start-SPAssignment and Stop-SPAssignment cmdlets must be used to avoid memory leaks.

    https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/get-spweb?view=sharepoint-ps

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.