Introduction
In this blog post we will be looking how to create Lists and Fields using PnP PowerShell. You can download and install PnP PowerShell here.
Solution
First you have to connect to SharePoint Online using PnP PowerShell.
Connect-PnPOnline –Url “site collection name” –Credentials (Get-Credential)Creating List
Generic List
$ListName = "Cohort"
$ListUrl = "Lists/Cohort"
New-PnPList -Title "ListName" -Url "ListUrl" -Template GenericList
Fields
Number
$NumberFieldString ='' Add-PnPFieldFromXml -List ListName -FieldXml $NumberFieldString
Text
$TextFieldString ='' Add-PnPFieldFromXml -List ListName -FieldXml $TextFieldString
Date
$DateFieldString = '' Add-PnPFieldFromXml -List $ListName -FieldXml $EndDateFieldString
Multi Lines
$MultiLines ='Yes/No' Add-PnPFieldFromXml -List $InstructorCohortListName -FieldXml $MultiLines
$Boolean ='Lookup' Add-PnPFieldFromXml -List $InstructorCohortListName -FieldXml $Boolean
#Please not that you have to give the Look up list guid for List Field $Lookup ='' Add-PnPFieldFromXml -List $CohortListName -FieldXml $Lookup