0

I have a requirement to create large number of columns in a SharePoint Online custom list through SharePoint Online Management Shell.

I can't find any script to get this done. I want the PowerShell script to read the CSV file and create columns in custom list.

I don't have expertise on PowerShell scripting, therefore seeking help from this community.

2 Answers 2

1

Here is a sample script for your reference:

#parameters
$SiteUrl = "<SiteUrl>"
$Username = "<Account>"
$Password = "<Password>"
$ImportCsv = "C:\Temp\Columns.csv"
$ListName = "<ListName>"

#Connect to PnPOnline
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline -Url $SiteUrl -Credential $cred

#Import CSV and create columns
Import-Csv $ImportCsv | ForEach-Object {
    #Name and Type are the column names in the CSV
    Add-PnPField -List $ListName -Type $($_.Type) -InternalName "$($_.Name)" -DisplayName "$($_.Name)"
}

And test outcome:

enter image description here

References: Add-PnPField. / Import-Csv.

0

You can create list columns in SharePoint online using PnP PowerShell.

It's hard to get the ready made script for all types of columns. However, if you understand the cmdlet, it is not difficult to create large number of columns in loop.

Related references/scripts:

  1. Create And Remove List And Fields In SharePoint Site Using PnP Powershell
  2. Add-PnPField: Create List Column in SharePoint using PowerShell

Official documentations:

  1. Add-PnPField
  2. Add-PnPFieldFromXml

Using PowerShell: Create a Column in a Destination Site Using PowerShell in SharePoint Online

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.