Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE :: Import Excel Data To SharePoint Online Using PowerShell
In this article, we will go through the steps required to import the Excel file data to SharePoint online list using PnP PowerShell. There are a lot of ways to import the data, but for this article, we will stick to PowerShell way. Here the credit goes to person Danile Finke who developed the Import Excel PowerShell module and made it available in PowerShell Gallery. Kudos to him.
Step 1
Open the PowerShell with Admin Privileges. Check if the PowerShell module ‘ImportExcel’ is installed. You can check the installed modules from PowerShell by running Get-Module in the PowerShell ISE or PowerShell Command window.
Get-Module
As you observed, in my case the ImportExcel module is installed.
Step 2
Check the availability of the module in PowerShell Gallery. You can do so by entering the below command.
Find-Module
The Find-Module queries the PowerShell Gallery and gets the information from it.
Step 3
Install the module “ImportExcel” by entering the below command in the PowerShell window.
Install-Module -Name ImportExcel -Scope AllUsers
Note: You may be prompted if you trust the repository. Select ‘Yes’.
Step 4
After installing you may have to import-module.
If you are not able to find the module try the import-module command.
Import-Module -Name ImportExcel
Step 6
Now check the Excel Columns by importing the excel data.
$data = Import-Excel -Path “C:\Temp\TestRecords.xlsx”
Here the columns marked in the screenshot above, are present in excel. Create a PS Custom Object accordingly. You can refer to the script section on how to do this.
Step 6
Check if the PnP PowerShell module is installed. If not check the article in the references, on how to install the PnP PowerShell module. If installed, import the module.
Import-Module -Name PnP.PowerShell
Step 7
Declare the following variables with the Site URL and the List Name where the excel data needs to be imported.
$SiteUrl = “https://contoso.sharepoint.com/sites/ContosoDev”
$ListName = “MyTestList”
Step 8
Initiate a connection to SharePoint online using the parameter -interactive
Connect-PnPOnline -url $SiteUrl -interactive
Note – Please note that the account running the script should have Site Collection Administrator rights.
Step 9
Read the excel data using the import-excel command and store it in a variable.
$data = Import-Excel -Path “C:\Temp\TestRecords.xlsx”
Step 10
Read each excel row data, and for each row record, update the SharePoint list using the Add-PnPListItem command.
Step 11
Validate the data in the SharePoint online list.
Complete Script
Conclusion
Thus, in this article, we have seen how to import the excel data to SharePoint online list using PnP PowerShell Module.
Print article | This entry was posted by Peter on February 3, 2023 at 5:08 am, and is filed under Other Related Post. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |