The following PowerShell code will add a new Boolean field named "Field Name" to the list called "List Name" on the "http://siteurl/" SharePoint installation. The script can of course be modified to add multiple columns, to multiple lists and the various other field types.
Add-PSSnapin Microsoft.SharePoint.PowerShell [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges( { $site = SPSite("http://siteurl/") $web = $site.RootWeb $spList = $web.Lists["List Name"] $spFieldType = [Microsoft.SharePoint.SPFieldType]::Boolean $spList.Fields.Add("Field Name",$spFieldType,$false) $spList.Update() } )
No comments:
Post a Comment