Forum Discussion
Create a Contact List with PowerShell in SharePoint 2013
- Aug 14, 2019
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
Here is a example to create 10 contact lists in a site:
$site = "http://michlee-sp2013"
$web = Get-SPWeb $site
$listcount = 10
$ListTemplate = $web.ListTemplates["Contacts"]
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++)
{
$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
THANK YOU! I am sorry, I am not very good at PowerShell and so I had to cut it up a bit to get it working. Thank you for the Create list 1-10, that worked great. I didn't know how to get it to work, so I tried to cut it up and this seemed to work. I don't know if it's the best. This is what I did to get them to create. THANK YOU again!
Add-PSSnapin Microsoft.SharePoint.Powershell -ea -0
$site = "https://servername/sites/States"
$web = Get-SPWeb $site
$ListTemplate = $web.ListTemplates["Contacts"]
#Create the Lists
$web.Lists.Add("AL","AL - Alabama",$listTemplate)
$web.Lists.Add("AK","AK - Alaska",$listTemplate)
$web.Lists.Add("AZ","AZ - Arizona",$listTemplate)
$web.Lists.Add("AR","AR - Arkansas",$listTemplate)
$web.Lists.Add("CA","CA - California",$listTemplate)
$web.Lists.Add("CO","CO - Colorado",$listTemplate)
$web.Lists.Add("CT","CT - Connecticut",$listTemplate)
$web.Lists.Add("DE","DE - Delaware",$listTemplate)
$web.Lists.Add("FL","FL - Florida",$listTemplate)
$web.Lists.Add("GA","GA - Georgia",$listTemplate)
$web.Lists.Add("HI","HI - Hawaii",$listTemplate)
$web.Lists.Add("ID","ID - Idaho",$listTemplate)
$web.Lists.Add("IL","IL - Illinois",$listTemplate)
$web.Lists.Add("IN","IN - Indiana",$listTemplate)
$web.Lists.Add("IA","IA - Iowa",$listTemplate)
$web.Lists.Add("KS","KS - Kansas",$listTemplate)
$web.Lists.Add("KY","KY - Kentucky",$listTemplate)
$web.Lists.Add("LA","LA - Louisiana",$listTemplate)
$web.Lists.Add("ME","ME - Maine",$listTemplate)
$web.Lists.Add("MD","MD - Maryland",$listTemplate)
$web.Lists.Add("MA","MA - Massachusetts",$listTemplate)
$web.Lists.Add("MI","MI - Michigan",$listTemplate)
$web.Lists.Add("MN","MN - Minnesota",$listTemplate)
$web.Lists.Add("MS","MS - Mississippi",$listTemplate)
$web.Lists.Add("MO","MO - Missouri",$listTemplate)
$web.Lists.Add("MT","MT - Montana",$listTemplate)
$web.Lists.Add("NE","NE - Nebraska",$listTemplate)
$web.Lists.Add("NV","NV - Nevada",$listTemplate)
$web.Lists.Add("NH","NH - New Hampshire",$listTemplate)
$web.Lists.Add("NJ","NJ - New Jersey",$listTemplate)
$web.Lists.Add("NM","NM - New Mexico",$listTemplate)
$web.Lists.Add("NY","NY - New York",$listTemplate)
$web.Lists.Add("NC","NC - North Carolina",$listTemplate)
$web.Lists.Add("ND","ND - North Dakota",$listTemplate)
$web.Lists.Add("OH","OH - Ohio",$listTemplate)
$web.Lists.Add("OK","OK - Oklahoma",$listTemplate)
$web.Lists.Add("OR","OR - Oregon",$listTemplate)
$web.Lists.Add("PA","PA - Pennsylvania",$listTemplate)
$web.Lists.Add("RI","RI - Rhode Island ",$listTemplate)
$web.Lists.Add("SC","SC - South Carolina",$listTemplate)
$web.Lists.Add("SD","SD - South Dakota ",$listTemplate)
$web.Lists.Add("TN","TN - Tennessee",$listTemplate)
$web.Lists.Add("TX","TX - Texas",$listTemplate)
$web.Lists.Add("UT","UT - Utah",$listTemplate)
$web.Lists.Add("VT","VT - Vermont",$listTemplate)
$web.Lists.Add("VA","VA - Virginia",$listTemplate)
$web.Lists.Add("WA","WA - Washington",$listTemplate)
$web.Lists.Add("WV","WV - West Virginia",$listTemplate)
$web.Lists.Add("WI","WI - Wisconsin",$listTemplate)
$web.Lists.Add("WY","WY - Wyoming",$listTemplate)