使用Powershell将csv导入SharePoint列表
问题描述:
我想从CSV导入数据到SharePoint列表,我从脚本获取的所有数据都是空白行。这里是我的代码:使用Powershell将csv导入SharePoint列表
# CSV path/File name
$contents = Import-Csv ".\Input.csv"
# Web URL
$web = Get-SPWeb -Identity "http://Zaxiyn/"
# SPList name
$list = $web.Lists["Technical Profile List"]
# Iterate for each list column
foreach ($row in $csv) {
$item = $list.Items.Add();
$item["Computer"] = $row.Computer;
$item["ItemOrder"] = $row.ItemOrder;
$item["Category"] = $row.Category;
$item["ItemName"] = $row.ItemName;
$item["ItemValue"] = $row.ItemValue;
$item.Update();
}
答
看起来你指的是不存在的变量。 csv文件内容保存在$ contents中,并且您的foreach语句使用$ csv,请试试这个:
foreach ($row in $contents) { ... }
非常感谢您的帮助,我简直不敢相信我错过了!如果我在特定文件夹中有多个csv,我将如何遍历它们以添加到SharePoint列表?我的想法是使用:ls * .csv | $ Get-Children中的文件“。\ csvfiles \”{...} – Emlinie
ls * .csv | foreach-object {$ contents = import-csv $ _。fullname; foreach($ content中的$ row)...} –
如果它解决了您的问题,请考虑将我的传统标记为答案 –