In this blog, we are going to retrieve all the fields from a list and will add/remove a field from a SharePoint list using PnP PowerShell. For that, first, we need to connect to the site.
To establish the connection, add this command.
$SiteUrl = Read-Host "Provide Site URL"
Connect-PnPOnline -Url $SiteUrl
#Executing this line will ask for credentials. Provide a username and password to connect.
To retrieve all fields, add the below command.
$Fields = Get-PnPField -List "Test"
To add a field to a list, add this command.
Add-PnPField -List "Test" -DisplayName "Designation" -InternalName "Designation" -Type MultiChoice -AddToDefaultView -Choices "HR","CEO", "DEVELOPER","TESTER"
To remove a field from list, execute this command.
Remove-PnPField -List "Test" -Identity "Designation"
Executing this command opens a popup window for confirmation of the field to be deleted.
Clicking on YES will remove the field from the list.