简体   繁体   English

PnP PowerShell - 将 CSV 上传到 SharePoint 列表

[英]PnP PowerShell - Upload CSV to SharePoint List

I'm looking for some help with PnP PowerShell.我正在寻找有关 PnP PowerShell 的帮助。 I have a script which takes a CSV file and uploads each row as an item to SharePoint Online (see below).我有一个脚本,它接受一个 CSV 文件并将每一行作为一个项目上传到 SharePoint Online(见下文)。 My question is, how do I get the script to skip items that already exist in the SharePoint Online list?我的问题是,如何获取脚本以跳过 SharePoint Online 列表中已存在的项目? Currently the script just uploads all rows within the CSV and creates some duplicates.目前,脚本只上传 CSV 中的所有行并创建一些重复项。

#Parameters
$SiteUrl = "{site}"
$ListName = "iPhone"

$CSVPath = "C:\Users\{user}\Documents\PowerShell\Upload SharePoint items from CSV\iphoneexport.csv"



#Get the CSV file contents
$CSVData = Import-CsV -Path $CSVPath

#Connect to site
Connect-PnPOnline $SiteUrl -Interactive


#Iterate through each Row in the CSV and import data to SharePoint Online List
ForEach ($Row in $CSVData)
{
Write-Host "Adding Item $($Row.'Asset Number')"


#Add List Items - Map with Internal Names of the Fields!
Add-PnPListItem -List $ListName -Values @{"Title" = $($Row.'Asset Number');

                        "User" = $($Row.User);

};

}

I'd be grateful for any advice anyone can give.我会很感激任何人可以提供的任何建议。

Many thanks,非常感谢,

Alex.亚历克斯。

As a workaround, you could enforce unique values for the Title column in list settings.作为一种解决方法,您可以在列表设置中为“标题”列强制执行唯一值。 As the below picture shows:如下图所示:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM