Automating SharePoint List Creation using PnP PowerShell allows you to quickly deploy multiple lists with predefined columns, views, and permissions.
What you can do?
- Create multiple lists automatically
- Define columns and metadata
- Set permissions and views
Step 1: Install and Import PnP PowerShell
If you haven’t installed PnP PowerShell, install it using:
Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force
Then, import the module:
Import-Module PnP.PowerShell
PnP PowerShell is ready!
Step 2: Connect to SharePoint
Before creating lists, connect to your SharePoint Online site:
$SiteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
Connect-PnPOnline -Url $SiteUrl -Interactive
🔹 Replace yourtenant
with your Microsoft 365 tenant name.
🔹 Replace yoursite
with your SharePoint site name.
Connected to SharePoint!
Step 3: Create a New SharePoint List
To create a new SharePoint list:
$ListName = "Project Tasks"
$ListDescription = "A list to track project tasks"
$TemplateType = "GenericList" # Options: GenericList, DocumentLibrary, Announcements, Contacts, etc.
New-PnPList -Title $ListName -Template $TemplateType -Description $ListDescription -OnQuickLaunch
Write-Host "SharePoint List '$ListName' created successfully!"
🔹 This creates a custom list named “Project Tasks”.
🔹 Add -OnQuickLaunch
to display it in the navigation bar.
List created successfully!
Step 4: Add Columns to the List
Now, let’s add columns to the “Project Tasks” list:
# Add a Text Column
Add-PnPField -List "Project Tasks" -DisplayName "Task Name" -InternalName "TaskName" -Type Text
# Add a Choice Column
Add-PnPField -List "Project Tasks" -DisplayName "Status" -InternalName "Status" -Type Choice -Choices "Not Started", "In Progress", "Completed"
# Add a Date Column
Add-PnPField -List "Project Tasks" -DisplayName "Due Date" -InternalName "DueDate" -Type DateTime
Write-Host "Columns added successfully!"
🔹 Supports column types like Text, Number, Choice, DateTime, Boolean, Lookup, User, Currency.
Columns added successfully!
Step 5: Create a Default View
Define a custom list view:
$ViewFields = @("TaskName", "Status", "DueDate") # Columns to show
Add-PnPView -List "Project Tasks" -Title "Active Tasks" -Fields $ViewFields -Paged -SetAsDefault
Write-Host "Default view created successfully!"
🔹 This sets up a custom default view with selected columns.
Custom view created successfully!
Step 6: Assign Permissions
To restrict access to the list:
$GroupName = "Project Team"
Set-PnPListPermission -Identity "Project Tasks" -Group $GroupName -AddRole "Edit"
Write-Host "Permissions assigned to $GroupName!"
Assigns Edit permissions to the “Project Team” group.
Permissions assigned successfully!
Step 7: Automate Multiple List Creation
To create multiple lists automatically, use a loop:
$Lists = @(
@{ Name="Projects"; Template="GenericList"; Description="List of all projects" },
@{ Name="Tasks"; Template="GenericList"; Description="List of tasks" },
@{ Name="Meetings"; Template="GenericList"; Description="List of meetings" }
)
foreach ($List in $Lists) {
New-PnPList -Title $List.Name -Template $List.Template -Description $List.Description -OnQuickLaunch
Write-Host "Created list: $($List.Name)"
}
Write-Host "All lists created successfully!"
Loops through an array and creates multiple lists in one go!
Multiple lists created successfully!
Step 8: Export and Import List Configurations
Export Existing List Configuration
If you want to replicate an existing list, export its structure:
Get-PnPSiteTemplate -Out "SiteTemplate.xml"
Write-Host "Site structure exported successfully!"
Import List Configuration to Another Site
To import the list structure to a new SharePoint site:
Apply-PnPSiteTemplate -Path "SiteTemplate.xml"
Write-Host "Site structure imported successfully!"
Easily copy lists from one site to another!
Step 9: Disconnect the Session
After automation, disconnect from SharePoint:
Disconnect-PnPOnline
Disconnected from SharePoint!