最近,因為新系統要上線,總是需要準備資料,把檔案里的資料匯入到SharePoint 串列當中,復制吧快速編輯功能還不給力,就想到寫個PowerShell 扔給BA去玩,
這里就舉個簡單的串列,結構如下:

我們需要的CSV檔案結構如下:

匯入CSV到List的PowerShell 命令如下:
Add-PSSnapin Microsoft.SharePoint.PowerShell #Read CSV file $CSVData = Import-CSV -path "D:\Data.csv" #Get SPWeb $web = Get-SPWeb -identity "http://sitecollection" #Get SPList $List = $web.Lists["ListName"] #Loop every Row in the CSV foreach ($Row in $CSVData) { #New SPListItem $Item = $List.Items.add() #Add SPColumn Value $item["Title"] = $row.Title $item["Name"] = $row.Name $item["Mark"] = $row.Mark $item.Update() Write-Host "Added: "$row.Name -ForegroundColor Green }
PowerShell 執行結果:

結束語
其實,整個代碼思路是很簡單的,讀取CSV檔案里的所有行,然后回圈插入到串列就好了,
如果運維或者BA的命令列能力比較強,自己都能夠搞定,因為語法是標準的PowerShell 語法,
更多常用PowerShell腳本,請關注 https://github.com/linyus
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/2339.html
標籤:SharePoint
