With this short article, I will tell you a quick script to create a list using PowerShell with different columns types. And here is the code that I used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
clear Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell try { $TestSiteUrl = "http:// sharepoint2013hostingnews.com" #provide site url in this variable $ListName = "KPIConfigList" #listName $ListDescription = "KPI config list" #list description $myTestWeb = Get-SPWeb -identity $TestSiteUrl #Get web object $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::GenericList #GenericList template write-host "Adding list" $ListName $myCustomList = $myTestWeb.Lists[$ListName] if($myCustomList -eq $null) { $lstId = $myTestWeb.Lists.Add($ListName,$ListDescription,$listTemplate) $myCustomList = $myTestWeb.Lists[$ListName] #Add columns $spFieldType = [Microsoft.SharePoint.SPFieldType]::Text $myCustomList.Fields.Add("TextField",$spFieldType,$false) #Add columns $spFieldType = [Microsoft.SharePoint.SPFieldType]::Number $myCustomList.Fields.Add("Order",$spFieldType,$false) #Add columns $spFieldType = [Microsoft.SharePoint.SPFieldType]::Boolean $myCustomList.Fields.Add("IsDefault",$spFieldType,$false) #Add columns $choices = New-Object System.Collections.Specialized.StringCollection $choices.Add("Client") $choices.Add("Unit") $spFieldType = [Microsoft.SharePoint.SPFieldType]::Choice $myCustomList.Fields.Add("Type",$spFieldType,$false,$false,$choices) #Update $myCustomList.Update() write-host "List created successfully" $ListName } else { write-host "List already exists" $ListName } } catch { write-host "Error" $_.exception $errorlabel = $true } finally { if($myTestWeb -ne $null) {$myTestWeb.Dispose()} if($errorlabel -eq $true){exit 1} else {exit 0} }exit 0 |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options