Removing Columns from a SharePoint List using PnP PowerShell

Loading

In SharePoint Online, columns (fields) store structured data in lists. Sometimes, you may need to remove unnecessary columns to simplify list management. Using PnP PowerShell, you can easily delete columns from a SharePoint list without manually navigating through the UI.

This guide covers:
How to connect to SharePoint Online
How to remove columns from a SharePoint list
How to verify the deletion


Prerequisites

Before proceeding, ensure you have:
✔️ Admin or Site Owner permissions
✔️ PnP PowerShell installed
✔️ The SharePoint site URL and list name


Step 1: Install and Import PnP PowerShell

If you haven’t installed PnP PowerShell, install it using:

Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force

Then, import the module:

Import-Module PnP.PowerShell

PnP PowerShell is ready!


Step 2: Connect to SharePoint Online

To remove a column, first, connect to the SharePoint site:

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive

🔹 Replace "yourtenant" with your tenant name
🔹 Replace "yoursite" with the site name where the list exists

Connected successfully!


Step 3: Get All Columns in a SharePoint List

Before deleting, list all columns in the SharePoint list:

# Get all columns in a list
Get-PnPField -List "Employee Directory" | Select Title, InternalName, TypeAsString

This command retrieves the Title, Internal Name, and Type of all columns.
Note down the Internal Name of the column you want to delete.


Step 4: Remove a Column from a SharePoint List

Use the Remove-PnPField command to delete a column.

1️⃣ Remove a Single Column

# Remove a column
Remove-PnPField -List "Employee Directory" -Identity "Department" -Force

🔹 "Employee Directory" → The list name
🔹 "Department" → Internal Name of the column
🔹 -ForceDeletes the column without confirmation

Column removed successfully!


2️⃣ Remove Multiple Columns

# Remove multiple columns
$columnsToRemove = @("EmployeeID", "Salary", "JoiningDate")

foreach ($column in $columnsToRemove) {
Remove-PnPField -List "Employee Directory" -Identity $column -Force
Write-Host "Removed column: $column"
}

This loops through the array and removes multiple columns.


3️⃣ Remove All Custom Columns

# Remove all custom columns except default ones
$defaultColumns = @("Title", "Created", "Modified", "Author", "Editor")
$columns = Get-PnPField -List "Employee Directory" | Where-Object { $_.InternalName -notin $defaultColumns }

foreach ($column in $columns) {
Remove-PnPField -List "Employee Directory" -Identity $column.InternalName -Force
Write-Host "Removed column: $($column.InternalName)"
}

This removes all custom columns while keeping default system columns.


Step 5: Verify Column Deletion

To ensure the column is deleted, run:

# Verify if the column still exists
Get-PnPField -List "Employee Directory" | Select Title, InternalName, TypeAsString

If the column is not listed, it has been successfully removed!


Common Errors & Troubleshooting

ErrorCauseSolution
Access DeniedInsufficient permissionsEnsure you have Admin or Site Owner rights
Cannot find field with identity 'Department'The column does not existRun Get-PnPField -List "ListName" to verify column names
The term 'Remove-PnPField' is not recognizedPnP PowerShell is not installedRun Import-Module PnP.PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *