Create Task List in SharePoint using PowerShell
Requirement: In SharePoint, create a task list using PowerShell!
PowerShell to create task list in SharePoint:
Let me show you how to create a task list in SharePoint using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables
$WebURL="https://intranet.crescent.com"
$ListName="Project Tasks"
$ListDescription ="Task list to manage project tasks"
#Task list template
$ListTemplate = [Microsoft.SharePoint.SPListTemplateType]::Tasks
#Get the Web
$Web = Get-SPWeb $WebURL
#Check if the task list exists already
$TaskList = $Web.Lists.TryGetList($ListName)
if($TaskList -ne $null)
{
Write-host "Task list '$($ListName)' exists already!" -ForegroundColor Red
}
else
{
#Create the task list
$Web.Lists.Add($ListName,$ListDescription,$ListTemplate) | Out-Null
#Set "Show in Quick Launch" property for the list
$TaskList = $Web.Lists[$ListName]
$TaskList.OnQuickLaunch = $True
$TaskList.Update()
Write-host "Task list '$($ListName)' Created successfuly!" -ForegroundColor Green
}
This PowerShell script creates a SharePoint task list.
To add a task in the Task List using PowerShell, use: Create a Task in SharePoint Task List using PowerShell