Apr 01 2022 06:27 AM - edited Apr 05 2022 02:56 AM
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()
}
Apr 02 2022 02:28 AM
Apr 04 2022 01:59 AM
Apr 04 2022 08:27 AM
Apr 05 2022 12:58 AM
Apr 05 2022 01:17 AM
Apr 05 2022 01:24 AM
Apr 05 2022 02:00 AM
Apr 05 2022 02:47 AM
Apr 05 2022 03:22 AM
Apr 05 2022 03:46 AM
Apr 05 2022 04:19 AM
Apr 05 2022 04:38 AM
Apr 05 2022 06:28 AM
Apr 05 2022 06:29 AM
Apr 05 2022 06:32 AM
Apr 05 2022 08:00 AM
as you make use of CSOM and SharePoint Online Management shell, I`d suggest to download the latest CSOM libraries from here:
https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM
and once downloaded load them into your current session.
The installed ones you are adding currently might not be compatible with SharePoint Online.
BTW. , you do not need to install those, they could be filed relative to the scripts´ location as well.
e.g. this is a shortened function I would use.
function get-assemblies {
$sCSOMPath= $scriptDir
$sCSOMRuntimePath=$sCSOMPath + "\Microsoft.SharePoint.Client.Runtime.dll"
$sCSOMClientPath=$sCSOMPath + "\Microsoft.SharePoint.Client.dll"
#$sCSOMUploadPath= $sCSOMPath +" \Microsoft.SharePoint.Client.Publishing.dll"
#Load SharePoint Online CSOM Assemblies
try{
Add-Type -Path $sCSOMClientPath | out-null
Add-Type -Path $sCSOMRuntimePath | out-null
}
catch {
Add-LogEntry $logFilePath $requestNumber $env:hostname 'error' "failed loading assemblies"
return Get-JsonStatus 1 "required dlls for SharePoint on $env:computername not found."
}
}
Apr 05 2022 08:12 AM
Apr 06 2022 01:53 AM
Thanks, when I use your technique I have no errors! On the other hand my items in my SharePoint list coming from my CSV file are empty :( Why I don't have my values displayed D: ?