Monday, January 12, 2015

Create New Custom List in SharePoint using PowerShell

Requirement: Add custom list to SharePoint using PowerShell.

create a sharepoint list using powershell

PowerShell to Create New List in SharePoint:
Here is the PowerShell script to create new list in SharePoint.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to create 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
            write-host "List with 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 new List
$ListName = "Customer Directory"

#Call the function to create new custom list
Create-List $SiteURL $ListName

This PowerShell script creates new custom list in SharePoint with "Title" column. If you want to add more columns to the list using PowerShell, Refer: How to Add Fields to SharePoint List using PowerShell.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...