Wednesday, December 14, 2011
Create List via PowerShell
# This script creates a List called computer inventory used in Lab 4 of the 10174 course
# make sure that you user has spshelladmin if not
Add-SPShellAdmin -Username CONTOSO\SP_Admin -Database (Get-SPContentDatabase "WSS_Content_Intranet_IT")
# Variable Declaration
$mysite = "http://intranet.contoso.com/sites/IT"
# Script begins here
$SPWeb = Get-SPWeb $mysite -AssignmentCollection $spAssignment
$SPTemplate = $SPWeb.ListTemplates["Custom List"]
$SPWeb.Lists.Add("ComputerInventory","Description",$SPTemplate)
$SPlist = $spweb.lists["computerinventory"]
$splist.title = "Computer Inventory"
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add(“Computer Name”,$spFieldType,$false)
$spList.Fields.Add(“Serial Number”,$spFieldType,$false)
$splist.update()$sp$
$spView = $spweb.GetViewl(mysite$+“/Lists/”+ $spList.Name + “/AllItems.aspx”)
$spField = $spList.Fields["Computer Name"]
$spView.ViewFields.Add($spField)
$spField = $spList.Fields["Serial Number"]
$spView.ViewFields.Add($spField)
$spView.Update()
Stop-SPAssignment $SPAssignment
ref
http://get-spscripts.com/2010/10/changing-sharepoint-list-settings-using.html
http://farhanfaiz.wordpress.com/2011/03/31/sharepoint-2010-powershell-script-%e2%80%93-create-list-add-column-in-custom-list-add-column-in-the-view/
No comments:
Post a Comment