Search This Blog

Friday, May 24, 2013

Add Custom List through Power Shell

save it .ps1 file and execute powershell(right click file and run as powershell)

Add-PSSnapin Microsoft.SharePoint.PowerShell
$SPSite = New-Object Microsoft.SharePoint.SPSite("");
#Open you web
$OpenWeb = $SpSite.OpenWeb();
$ListName = "Country_Region"
#list description
$ListDescription = "Region information list"
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::GenericList  #GenericList template

write-host "Adding list" $ListName
$myCustomList = $OpenWeb.Lists[$ListName]
if($myCustomList -eq $null)
$lstId = $OpenWeb.Lists.Add($ListName,$ListDescription,$listTemplate)

write-host "list created successfully"
#Open Your List
$List = $OpenWeb.Lists[$ListName];
#Add User Field to list
$List.Fields.Add("Country", "Text", $User)
#Add TextField to list
$List.Fields.Add("Region", "Text", $Text)

#Update view
$Views = $List.Views["All Items"]


No comments:

Post a Comment