Forum Discussion

Matthew Carter's avatar
Matthew Carter
Iron Contributor
Aug 14, 2019
Solved

Create a Contact List with PowerShell in SharePoint 2013

  I am able to find a way to create a bunch of Document Libraries in SharePoint 2013 using PowerShell, unfortunately after I created this, with the help of the website at the bottom, I realized that...
  • mikeleemsft's avatar
    Aug 14, 2019

    Matthew Carter 

    Here is a example to create 10 contact lists in a site:

    Add-PSSnapin Microsoft.SharePoint.Powershell -ea -0
    $site = "http://michlee-sp2013"
    $web = Get-SPWeb $site
    $listcount = 10
    $ListTemplate = $web.ListTemplates["Contacts"]
     
    #Start Loop for List creation based on $listcount in ROOT Library
     for($l=1; $l -le $listcount; $l++)
     
    #Create the Lists
     {
     $web.Lists.Add("Contact List $l","Contac List $l",$listTemplate)
     Write-Host "####################################" -ForegroundColor Green
     write-host "List $l created in $site" -ForegroundColor Green
     Write-Host "####################################" -ForegroundColor Green
     
    # While creating lists put new items in it based on the $itemcount
     if ($l -le $listcount )
     
    {
     #Start Loop for List Item creation in ROOT Library
     for ($i=1; $i -le $itemcount; $i++)
     {
     #Create List Item
     $list = $web.Lists["List $l"]
     $newItem = $list.AddItem()
     $newItem["Title"] = "Item $i"
     $newItem.Update()
     write-host "Item: $i created in list: $l" -ForegroundColor Yellow
     Write-Host "##############################" -ForegroundColor Yellow
     }
     }
     }


    See:  https://techcommunity.microsoft.com/t5/SharePoint-Support-Blog/SharePoint-Site-Population-Script-for-Testing/ba-p/308647

Resources