Create a New SharePoint List and Add a Choice Field to it Using PNP

Introduction 

 
Nowadays, there is high demand for PnP, as there is less execution of codes and all is done by executing a number of commands in PnP.
  • Procedure
  • Connect to the site
At first, connect to the site where you want to create a new list and the chosen field of it.
 
To connect to the SharePoint list, you must run the following PnP command, as given below.
 
$credentials = Get-Credential
$siteurl = "https://softreetechss.sharepoint.com"
Connect-PnPOnline -Url $siteurl -Credentials $credentials
 
In the place of siteurl, give the URL of your site.
 
After executing the command, you will be prompted for the credentials of the site, as shown below.
 
 Create A New SharePoint List And Adding A Choice Field In It By Using
 
After providing the credentials of your site, you can create a new list in your site.
 
Create a Newlist
 
To create a new list in your site, you should run the following command, as given below.
 
Add-PnPField -List"Demo4 Test" -DisplayName"Demo4"
 
After running the script, you will notice that the newlist has been created in your site, as shown below.
 
Create A New SharePoint List And Adding A Choice Field In It By Using
 
Add a Choice field in Newly Created List
 
To create the new choice field in the newly created list, you should run the following command, as given below.
 
Add-PnPField -List"Demo4Test" -DisplayName"Language" -Type Choice -AddToDefaultView -Choices"English","French","Dutch"
 
After running the script, you will notice that the new field is created in your list, as shown below.
 
Create A New SharePoint List And Adding A Choice Field In It By Using
 
After creating the field it is time to use those choices which we added through the command and those choices are, 1. English,2. French,3. Dutch.
 
To use these choices you need to add an item in the newly created list. You can see these choices as shown below.
 
Create A New SharePoint List And Adding A Choice Field In It By Using
 
Now you can select any of these choices as per your requirement, then click on save.
 
After that, you will see that the new item with its selected field is ready, as shown below.
 
Create A New SharePoint List And Adding A Choice Field In It By Using
 

Conclusion

 
To all dear readers, in this blog, I have explained to create a new list and adding a choice field in it using PnP. I hope you enjoyed it.