-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateList.ps1
More file actions
41 lines (34 loc) · 1.28 KB
/
CreateList.ps1
File metadata and controls
41 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Function to create a custom list
Function Create-List($SiteURL, $ListName)
{
#Set the Error Action
$ErrorActionPreference = "Stop"
Try {
$Web = Get-SPWeb -Identity $SiteURL
$ListTemplate = [Microsoft.SharePoint.SPListTemplateType]::GenericList
#Check if List with specific name exists
if($Web.Lists.TryGetList($ListName) -eq $null)
{
$List = $Web.Lists.Add($ListName, $ListName, $ListTemplate)
write-host "List Created Successfully!" -ForegroundColor Green
}
else
{
write-host "List with a specific name already exists!" -ForegroundColor Red
}
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
}
finally {
#Reset the Error Action to Default
$ErrorActionPreference = "Continue"
}
}
#Parameters to create a new List
$SiteURL="http://intranet.crescent.com/"
$ListName = "Customer Directory"
#Call the function to create a new custom list
Create-List $SiteURL $ListName
#Read more: https://www.sharepointdiary.com/2015/01/create-new-custom-list-in-sharepoint-using-powershell.html#ixzz7MK57AX7X