PnP provisioning is a community-driven platform that enables fast development of components that define your application infrastructure & the content to some extent. When we say infrastructure, its the underlying libraries, lists, pages, columns, content types that form the basis of any SharePoint site. In this article, we will see how to create & remove SharePoint list and fields using PnP PowerShell.
Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.
Connect to Site
Before connecting to the SharePoint site, we need to get Credentials by using the Get-Credential cmdlet which creates a credential object for a specified username and password. You can use the credential object in security operations. By default, an authentication dialog box appears to prompt the user like the below example picture.
Then connect to SharePoint site using Connect-PnPOnline cmdlet. The required parameters are -Url and-Credential. In -Url Parameter passes the site URL and in -Credential it passes the Get-Credential.
The following code snippet helps to connect SharePoint sites.
Create SharePoint List
The list can be created by using New-PnPList cmdlet on SharePoint Site. The required parameters are,
- Template – Type of list to created
- Title -Title of the list
The following cmdlets help to create SharePoint lists on the SharePoint site.
Remove SharePoint List
The list can be removed by using Remove-PnPList cmdlet on SharePoint Sites. The required parameters are,
Identity – The ID or Title of the list
The following cmdlets help to remove SharePoint list on the SharePoint site.
Remove the list named Hubfly-Team, Before deleting ask for a confirmation.
Removes the list named Hubfly-Team without asking for confirmation.
Removes the list named ‘HubflyTeam’ and saves to the Recycle Bin.
Create SharePoint Fields
The fields can be created by using Add-PnPField cmdlet on the SharePoint site. The required parameters are,
- DisplayName – The display name of the field
- Field – The name of the field, its ID or an actual field object that needs to be added
- InternalName – The internal name of the field
- Type – The type of the field like Choice, Note, MultiChoice
The following cmdlets helps to create SharePoint fields on the SharePoint site,
Remove SharePoint Fields
The fields can be removed by using Remove-PnPField cmdlet on the SharePoint site. The required parameters are,
Identity â€“ The field object or name to remove
The following cmdlets help to remove SharePoint list on the SharePoint site
- Remove-PnPField -Identity NameHF
Remove the Field named “NameHF“, before removing ask for a confirmation.
- Remove- PnPField -Identity NameHF -Force
Remove the Field named “NameHF” without asking for confirmation.
Thus, you have learned how to create and remove SharePoint Lists and Fields programmatically using PnP PowerShell commands. PnP PowerShell is supported by SharePoint Online. The operations mentioned above, are tested on SharePoint Online environments.