Create an item in a Sharepoint list from a Powershell script

Copper Contributor

Hello,
I have a Sharepoint listing called "Membres" on one of my sites.
I would like to create a new item in this list from a PowerShell script but I can't. This tells me an error.
Here is the script I am using:

 

 

 

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set Config Parameters
$SiteURL="https://cgigodev.sharepoint.com/sites/TeletravailCGIGO"
$ListName="Membres"
 
Try { 
    #Get Credentials to connect
    $Cred= Get-Credential
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Get the List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
  
    #sharepoint online powershell add list item
    $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation  
    $ListItem = $List.AddItem($ListItemInfo)
     
    #Set Column Values
    $ListItem["Title"] = "A"
    $ListItem["Manager"] = "A"
    $ListItem["Lundi"] = "Télétravail"
    $ListItem["Mardi"] = "Télétravail"
    $ListItem["Mercredi"] = "Télétravail"
    $ListItem["Jeudi"] = "Télétravail"
    $ListItem["Vendredi"] = "Télétravail"
 
 
    #Apply changes to list
    $ListItem.Update()
    $Ctx.ExecuteQuery()
  
    Write-host -f Green "New Item has been added to the List!"
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}  

 

 

 

 

And here is the error it gives me:

 

 

 

applet de commande Get-Credential à la position 1 du pipeline de la commande
Fournissez des valeurs pour les paramètres suivants :
Error: Exception lors de l'appel de « ExecuteQuery » avec « 0 » argument(s) : « Des données non valid
es ont été utilisées pour mettre à jour l'élément de liste. Le champ que vous essayez de mettre à jou
r est peut-être en lecture seule. »

 

 

 

Could you help me please ? 😞 Thank you in advance !

1 Reply
You posted your question twice? https://techcommunity.microsoft.com/t5/windows-powershell/create-an-item-in-a-sharepoint-list-from-a... is the one from yesterday...

Could it be, I used Google Translate for the error message, that the list is Read-Only / Does your account have enough permissions?