In SharePoint Online, we create lists and libraries to store information and documents. It is easy to create a list in a SharePoint site using the browser, but it is a little different when you create a SharePoint list using PowerShell.
In this tutorial, I will explain how to create a list in SharePoint Online using PowerShell and PnP PowerShell.
Create a List in SharePoint Online using PowerShell
In the first example, I will show you how to create a list in SharePoint Online using the SharePoint management shell.
Below is the complete PowerShell script for creating a custom list named “Project Tasks” on the SharePoint site.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerPlatformFAQs"
# Define Variables
$listTitle = "Project Tasks"
$listDescription = "A list to track project tasks."
$UserName = "bijay@szg52.onmicrosoft.com"
$Password = "Enter Your Password"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$Ctx.Credentials = $Cred
$web = $ctx.Web
# Create the list
$listCreationInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInfo.Title = $listTitle
$listCreationInfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]::GenericList
$list = $web.Lists.Add($listCreationInfo)
$list.Description = $listDescription
$list.Update()
$ctx.ExecuteQuery()I executed the above script successfully; you can see below:

Once the script is executed successfully, when you open the SharePoint Online site, you can see the list was created successfully.

Check out Create, Read, Update, and Delete an Item from a SharePoint Online List using PnP PowerShell
Add Columns to SharePoint List using PowerShell
Using PowerShell, let me show you how to add columns to a SharePoint list.
Single Line of Text Column
Below is the code to a single line of text column in a SharePoint list.
# Add a single line of text column
$fieldXml = "<Field DisplayName='Task Name' InternalName='TaskName' Type='Text' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()If you want to have additional settings you can change the script like below:
# Add a single line of text column with additional settings
$fieldXml = "<Field DisplayName='Task Description' InternalName='TaskDescription' Type='Text' Required='TRUE' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()Choice Column
Below is the code to create a choice column in a SharePoint Online list.
# Add a choice column
$fieldXml = "<Field DisplayName='Priority' InternalName='Priority' Type='Choice' Format='Dropdown'>
<CHOICES>
<CHOICE>High</CHOICE>
<CHOICE>Medium</CHOICE>
<CHOICE>Low</CHOICE>
</CHOICES>
<Default>Medium</Default>
</Field>"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()For additional settings in a choice column, you can write the script like below:
# Add a choice column with additional settings
$fieldXml = "<Field DisplayName='Status' InternalName='Status' Type='Choice' Format='Dropdown' Required='TRUE'>
<CHOICES>
<CHOICE>Not Started</CHOICE>
<CHOICE>In Progress</CHOICE>
<CHOICE>Completed</CHOICE>
</CHOICES>
<Default>Not Started</Default>
</Field>"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()Check out Add a Choice Column to a SharePoint Online List Using PnP PowerShell
Yes/No Column
Here is the script to add a Yes/No column into a SharePoint Online list.
# Add a yes/no column
$fieldXml = "<Field DisplayName='Completed' InternalName='Completed' Type='Boolean' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()Person or Group Column
Here is the PowerShell script to create a person or group column in a SharePoint Online list.
# Add a person or group column
$fieldXml = "<Field DisplayName='Assigned To' InternalName='AssignedTo' Type='User' UserSelectionMode='PeopleAndGroups' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()Below is the complete PowerShell script that will create the SharePoint Online list and add additional columns.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerPlatformFAQs"
# Define Variables
$listTitle = "Project Tasks"
$listDescription = "A list to track project tasks."
$UserName = "bijay@szg52.onmicrosoft.com"
$Password = "Enter Your Password"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
# Create a new list
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$web = $ctx.Web
$listCreationInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInfo.Title = $listTitle
$listCreationInfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]::GenericList
$list = $web.Lists.Add($listCreationInfo)
$list.Description = $listDescription
$list.Update()
$ctx.ExecuteQuery()
# Add a single line of text column
$fieldXml = "<Field DisplayName='Task Name' InternalName='TaskName' Type='Text' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Add a choice column
$fieldXml = "<Field DisplayName='Priority' InternalName='Priority' Type='Choice' Format='Dropdown'>
<CHOICES>
<CHOICE>High</CHOICE>
<CHOICE>Medium</CHOICE>
<CHOICE>Low</CHOICE>
</CHOICES>
<Default>Medium</Default>
</Field>"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Add a yes/no column
$fieldXml = "<Field DisplayName='Completed' InternalName='Completed' Type='Boolean' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Add a person or group column
$fieldXml = "<Field DisplayName='Assigned To' InternalName='AssignedTo' Type='User' UserSelectionMode='PeopleAndGroups' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Add a single line of text column with additional settings
$fieldXml = "<Field DisplayName='Task Description' InternalName='TaskDescription' Type='Text' Required='TRUE' />"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Add a choice column with additional settings
$fieldXml = "<Field DisplayName='Status' InternalName='Status' Type='Choice' Format='Dropdown' Required='TRUE'>
<CHOICES>
<CHOICE>Not Started</CHOICE>
<CHOICE>In Progress</CHOICE>
<CHOICE>Completed</CHOICE>
</CHOICES>
<Default>Not Started</Default>
</Field>"
$list.Fields.AddFieldAsXml($fieldXml, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$ctx.ExecuteQuery()
# Disconnect from SharePoint Online
Disconnect-SPOServiceThis is how to create a list in SharePoint Online and add additional columns to it.
Read Delete and Recover a SharePoint Online Site Using PowerShell and PnP PowerShell
Create a SharePoint Online List using PnP PowerShell
Now, let me show you how to create a SharePoint Online list using PnP PowerShell.
In PnP PowerShell, you can use the New-PnPList cmdlet to create a list on the SharePoint Online site.
Here is the complete PowerShell script:
# Create a new list
$siteUrl = "https://szg52.sharepoint.com/sites/MarketingTeam"
Connect-PnPOnline -Url $siteUrl -Credentials (Get-Credential)
New-PnPList -Title "Marketing Tasks" -Template GenericListOnce you execute the above PowerShell script, you can see the output in the screenshot below:

Now, if you open your SharePoint site, you can see the list created successfully using PnP PowerShell.

This is how to create a custom list in the SharePoint Online site using PnP PowerShell.
If you want to add columns to the SharePoint list, you can use the below script. I have explained how to add a single line text column, choice column, yes/no column, person or group column, etc.
# Add a single line of text column
Add-PnPField -List "Project Tasks" -DisplayName "Task Name" -InternalName "TaskName" -Type Text
# Add a choice column
Add-PnPField -List "Project Tasks" -DisplayName "Priority" -InternalName "Priority" -Type Choice -AddToDefaultView `
-Choices "High", "Medium", "Low" -DefaultValue "Medium"
# Add a yes/no column
Add-PnPField -List "Project Tasks" -DisplayName "Completed" -InternalName "Completed" -Type Boolean -AddToDefaultView
# Add a person or group column
Add-PnPField -List "Project Tasks" -DisplayName "Assigned To" -InternalName "AssignedTo" -Type User -AddToDefaultViewIf you want to have some additional settings, you can write like below, here I have added a few properties like -Required, -DefaultValue, etc.
# Add a single line of text column with additional settings
Add-PnPField -List "Project Tasks" -DisplayName "Task Description" -InternalName "TaskDescription" -Type Text `
-Required $true -AddToDefaultView
# Add a choice column with additional settings
Add-PnPField -List "Project Tasks" -DisplayName "Status" -InternalName "Status" -Type Choice -AddToDefaultView `
-Choices "Not Started", "In Progress", "Completed" -DefaultValue "Not Started" -Required $trueHere is the complete PowerShell script:
# Define Variables
$siteUrl = "https://szg52.sharepoint.com/sites/MarketingTeam"
$listTitle = "Project Tasks"
# Connect to SharePoint Online
Connect-PnPOnline -Url $siteUrl -Credentials (Get-Credential)
# Create a new list
New-PnPList -Title $listTitle -Template GenericList
# Add a single line of text column
Add-PnPField -List $listTitle -DisplayName "Task Name" -InternalName "TaskName" -Type Text -AddToDefaultView
# Add a choice column
Add-PnPField -List $listTitle -DisplayName "Priority" -InternalName "Priority" -Type Choice -AddToDefaultView `
-Choices "High", "Medium", "Low" -DefaultValue "Medium"
# Add a yes/no column
Add-PnPField -List $listTitle -DisplayName "Completed" -InternalName "Completed" -Type Boolean -AddToDefaultView
# Add a person or group column
Add-PnPField -List $listTitle -DisplayName "Assigned To" -InternalName "AssignedTo" -Type User -AddToDefaultView
# Add a single line of text column with additional settings
Add-PnPField -List $listTitle -DisplayName "Task Description" -InternalName "TaskDescription" -Type Text `
-Required $true -AddToDefaultView
# Add a choice column with additional settings
Add-PnPField -List $listTitle -DisplayName "Status" -InternalName "Status" -Type Choice -AddToDefaultView `
-Choices "Not Started", "In Progress", "Completed" -DefaultValue "Not Started" -Required $true
# Disconnect from SharePoint Online
Disconnect-PnPOnlineConclusion
When you want to create lists in a SharePoint production environment, you mostly use PowerShell or PnP PowerShell. In this tutorial, I have explained how to create a list in SharePoint Online using PowerShell and PnP PowerShell. I have also explained how to add columns to a SharePoint Online list using PnP PowerShell and PowerShell.
You may also like:
- Disable Versioning in a SharePoint Library Using PnP PowerShell
- Connect-SPOService : Current site is not a tenant administration site
- Delete All Items from a SharePoint List using PnP PowerShell
- Get Count of Items in SharePoint List using PnP PowerShell
- Check if a List Exists in SharePoint Site using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.