Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Thursday, June 19, 2014

How To: Create new list in sharepoint using powershell: 2013/2010/2007

Below code will help us to create a SharePoint list through PowerShell:
 
==================================================================================

$siteURL= "your site URL"

$ListName ="List Name"

$ListName1 ="ListName1"

==================================================================================

$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()

$TemplateType = $docWeb.ListTemplates["Custom List"]

function Create-SPList([string]$listName, [string]$description)
{
 $exLst = $docWeb.Lists[$listName]

        //Create new list if already doesn't exists
 if($exLst -eq $null)
 {
  Write-Host "`n List does not exist. Creating $listName list`n"
  [void]$docWeb.Lists.Add($listName, $description, $TemplateType)
  $docWeb.Update()
 }  
}


==================================================================================

//To create list name

Create-SPList -listName  $ListName   -description "List Description"

Create-SPList -listName1 $ListName1  -description "List Description1"

===================================================================================
Please let me know if face any issues while creating list through powershell.

Thanks,
Sasi kumar Reddy

No comments:

Post a Comment