Hi,
I’m not a professional tech person, but I’m trying to write a Powershell script to upload items from a CSV file into a SharePoint list. I’ve never used Powershell before, but I’ve found a few scripts online to use as templates. However, the one I found that gives examples for every content type is supposed to be run on the SharePoint server. I found another one I think can run on your local computer – which is what I need – however, the code is totally different and it only has text and lookup columns. I need text, date, and number columns, so I’m not sure how to adapt that code to work for my column types.
Would anybody be able to help me out? Keeping in mind that I have very little background knowledge, I need Powershell code to upload a local CSV file to a SharePoint list that has some text, one date, and 101 number columns. I need to execute the Powershell on a local computer.
Here’s what my list settings look like.
Here’s some code I also found. I think this is what I’m looking for, but 1) It doesn’t have any code for date or number columns, 2)even for the text columns in this code, I’m having a hard time telling which things are the SharePoint column name and which are the CSV column names, and 3)I don’t need any lookup fields. Any insights anyone can offer would be greatly appreciated.[apcode language=”powershell”]
#Setup the correct modules for SharePoint Manipulation if ((Get - PSSnapin - Name Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue) - eq $null) { Add - PsSnapin Microsoft.SharePoint.PowerShell } $host.Runspace.ThreadOptions = "ReuseThread" #Open SharePoint List $SPServer="https://mycompany.sharepoint.com/sites/PFBLMHR/Testing" $spWeb = Get-SPWeb $SPServer $SPAppList="/Lists/TestMaster/" $spData = $spWeb.GetList($SPAppList) $DatFile="G:\Personality Data\data.csv" #Get Data from Data CSV File $FileExists = (Test - Path $InvFile - PathType Leaf) if ($FileExists) { "Loading $DatFile for processing..." $tblData = Import - CSV $DatFile } else { "$DatFile not found - stopping import!" exit } foreach($row in $tblData) { "Adding entry for " + $row. "Title".ToString() $spItem = $spData.AddItem() $spItem["Title"] = $row. "Title".ToString() $spItem["Subject"] = $row. "Claim".ToString() $looValue1 = $row. "Sales".ToString() $spItem.Update() } "---------------" "Upload Complete"
[/apcode]
Hi,
You will need to check CSOM for SharePoint Online to manipulate the list.
Here’s a sample post:
https://blogs.technet.microsoft.com/french_sharepoint_gbs_blog/2014/04/08/how-to-manage-your-o365-sites-with-powershell-and-csom/
There will be differences on the PowerShell commands which is a bit confusing when starting with it.