How to Create a List with All Possible Columns in SharePoint Online Using PNP PowerShell Script
Kavali Rakesh (H1B holder with valid work Authorization)
Senior SharePoint Online Developer | Office 365 | Power Platform | PowerApps | Power Automate | PowerBI | Migration Expert | SPFX | React | Team Lead | Frontend Developer | ASP.NET MVC | .NET Core
SharePoint Online allows users to create lists to store and organize data. Each list can contain multiple columns with different types of data, such as text, choice, multiple choice, people picker, lookup, and more. While creating a list with several columns can be time-consuming, PowerShell scripting can automate this process and save time. In this article, we will guide you through the process of creating a list with all possible columns in SharePoint Online using a PowerShell script.
#SharePointOnline #PnP #PowerShell #ListCreation #ListColumns #SingleLineOfText #MultipleLinesOfText #Choice #MultipleChoice #DateTime #YesNo #Currency #Hyperlink #PersonOrGroup #lookup
# Connect to SharePoint Onlin
Connect-PnPOnline -Url https://<your site>.sharepoint.com/sites/<your site> -UseWebLogin
# Define the list name
$listName = "<your list name>"
# Create a new list
New-PnPList -Title $listName -Template GenericList
# Add columns to the list
Add-PnPField -List $listName -DisplayName "Single Line of Text" -InternalName "SingleLineTextField" -Type Text -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Multiple Lines of Text" -InternalName "MultiLineTextField" -Type Note -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Choice" -InternalName "ChoiceColumn" -Type Choice -Choices "Choice1","Choice2","Choice3" -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Multiple Choice" -InternalName "MultiChoiceColumn" -Type MultiChoice -Choices "Choice1","Choice2","Choice3" -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Date and Time" -InternalName "DateTimeColumn" -Type DateTime -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Yes/No" -InternalName "BooleanColumn" -Type Boolean -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Currency" -InternalName "CurrencyColumn" -Type Currency -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Hyperlink" -InternalName "HyperlinkColumn" -Type URL -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Person or Group" -InternalName "PersonOrGroupColumn" -Type User -AddToDefaultView
Add-PnPField -List $listName -DisplayName "Lookup" -InternalName "LookupColumn" -Type Lookup -LookupList "Lists/Contacts" -LookupField "ID" -AddToDefaultViewe