Upload excel Document items to Sharepoint list using PnP PowerShell

Occasional Contributor

Actually, I am able to upload Excel items to the SharePoint list using PnPPowershell, only the date, and lookup columns I am not able to upload.

please help on this, actually, the code is:


$SiteUrl = "https://SiteName"
$ListName = "Contacts"
$CSVPath = "Folder Path"

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

#Connect to site
Connect-PnPOnline $SiteUrl
#Iterate through each Row in the CSV and import data to SharePoint Online List
ForEach ($Row in $CSVData)
Write-Host "Adding Contact $($Row.FirstName)"
$NewDate = (Get-Date).tostring("yyyyMMdd")
#$NewDate = [datetime]::parseexact($NewDate,'dd/MM/yyyy HH:mm',$null)
# [datetime]::parseexact($NewDate, 'dd-MMM-yy', $null).ToString('yyyy-MM-dd')
#Add List Items - Map with Internal Names of the Fields!
Add-PnPListItem -List $ListName -Values @{"FirstName" = $($Row.FirstName);
"LastName" = $($Row.LastName);
"Mobile" = $($Row.Mobile);
"Person" = $($Row.Person);
"Choice" = $($Row.Choice);
"StartDate" = $($Row.StartDate);




Error: Add-PnPListItem : String was not recognized as a valid DateTime.

0 Replies