Wednesday, 25 February 2015

Powershell Import Data from csv with special characters

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue ############## PARAMETERS #################### $WebUrl = "Enter the sitecollection url" $Listname = "Enter the Listname" #Convert CSV to UTF-8 with special characters Get-Content E:\Tempfolder\testCSV.csv | Out-File E:\Tempfolder\testCSV.csv -Encoding utf8 #Get the CSV file and connect to the SharePoint list $DataSet = import-csv -Delimiter ";" -Path E:\Tempfolder\testCSV.csv" -Encoding Unicode ######### Add to SPList ######## $spWeb = Get-SPWeb -identity $WebUrl  #  Get SPWeb $list = $spWeb.Lists[$Listname] # Get SPList for($i = 0; $i -le $DataSet.Count; $i++) { #Read current row $row = $DataSet[$i] $item = $list.Items.Add(); $item["SPColumn1"] = $row.'Column1' $item["SPColumn2"] = $row.'Column2' $item["SPColumn3"] = $row.'Column3' $item["SPColumn_n"] = $row.'Column_n' $item.Update() }

No comments:

Post a Comment

Create Sites, Lists and Libraries in SharePoint 2016

Source:YouTube