Forum Discussion
444456464
Apr 01, 2022Copper Contributor
Import items from a CSV file to a Sharepoint Online list
Hello,
I made a PowerShell script to import items from a CSV file to a Sharepoint Online list. Except that my code does not work because I have this error: "Get-SPOUser : Le terme «Get-SPOUser» n'est pas reconnu comme nom d'applet de
commande, fonction, fichier de script ou programme exécutable. Vérifiez
l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin
d'accès est correct et réessayez."
My "Manager" item is a People Picker.
Can you help me please 😞 ?
My code :
#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"
##Variables for Processing
$SiteUrl = "https://abc/abc"
$ListName="Membres"
$ImportFile ="C:\Scripts\Equipe Romain.csv"
$UserName="abcd"
$Password ="1234"
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials
#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)
#Get the Data from CSV and Add to SharePoint List
$data = Import-Csv $ImportFile
Foreach ($row in $data) {
#add item to List
$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$Item = $List.AddItem($ListItemInfo)
$item["Title"] = $row."Nom Prenom"
#Set the People Picker Field value
$item["Manager"] = Get-SPOUser -Identity $row.Manager -web "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaa/"
$item["Lundi"] = $row.Lundi
$item["Mardi"] = $row.Mardi
$item["Mercredi"] = $row.Mercredi
$item["Jeudi"] = $row.Jeudi
$item["Vendredi"] = $row.Vendredi
$Item.Update()
$Context.ExecuteQuery()
}
- Did you import the module by installing it from here https://www.microsoft.com/en-us/download/details.aspx?id=35588 and by running Import-Module Microsoft.Online.Sharepoint.PowerShell
- 444456464Copper ContributorI just did it, and suddenly now I have this error in addition 😞 : Import-Module : Le module «Microsoft.Online.Sharepoint.PowerShell» spécifié n'a pas été
chargé, car aucun fichier de module valide n'a été trouvé dans un répertoire de module.
Au caractère- Install-Module Microsoft.Online.Sharepoint.PowerShell does work?