05 Jun Creating lists and fields in SharePoint with PnP-PowerShell
Having a talk with a customer I found out that they had trouble creating new lists and adding fields to them in their environment. The main reason they were using either SharePoint Designer or the UI of SharePoint was that they found it very difficult to create a list and new fields with PowerShell.
Well, here is a quick snack recipe on how to create lists and fields in SharePoint (in my case I will use my office365 dev site but you can also do it on-premises).
First of all, we need to download the PnP-PowerShell from github here
Now we are ready, start Windows PowerShell ISE and type the following in a new script window
Connect-SPOnline -Url "<your site here>" -Credentials(Get-Credential '<a valid SharePoint User>')
#Create the list
$listTitle = "Expenses"
New-SPOList -Title "Expenses" -Url "expenses" -Template GenericList -EnableVersioning
#Create the fields
Add-SPOField -List $listTitle -DisplayName "Amount" -InternalName "SPAmount" -Type Currency -AddToDefaultView
Add-SPOField -List $listTitle -DisplayName "Approved" -InternalName "SPApproved" -Type Boolean -AddToDefaultView
#pass choices as an array
$choices = "Hardware","Software","Traninng"
Add-SPOField -List $listTitle -DisplayName "Expense Category" -InternalName "SPExpCategory" -Type Choice -Choices $choices -AddToDefaultView
What we have achieved is to create a new list and add three new columns to it.
That’s it. Enjoy.