Delete unused workflow status columns in SharePoint list views using PowerShell

Delete unused workflow status columns in SharePoint list views using PowerShell

SharePoint 2010 seems to be better than 2007 for removing workflow status columns from list views after a workflow has been removed or updated, but it does still leave them behind every now and again.
I have been unable to trace exactly why this happens, but rather than waste time looking, I decided to write a quick PowerShell script to remove these columns as they cannot be deleted from the UI. This script works as a function – meaning that there are two parts to running it in the SharePoint 2010 Management Shell. First, you have to run the script shown below:

function Delete-WorkflowColumn ($webURL, $listName, $columnName) {     #Setup variables from the user input     $web = Get-SPWeb $webURL     $list = $web.Lists[$listName]     $column = $list.Fields[$columnName]        #Make sure the column is not hidden or read only     $column.Hidden = $false     $column.ReadOnlyField = $false     $column.Update()     #Delete column and dispose of the web object     $list.Fields.Delete($column)     write-host “Deleted column”     $web.Dispose() }

Once the function has been run, you can call it to actually remove a column with the following command:

Delete-WorkflowColumn -webURL http://portal -listName “Documents” -columnName “Approval Workflow (Previous Version:1/17/2011 8:45:01 PM)”

The example above deletes the “Approval Workflow (Previous Version:1/17/2011 8:45:01 PM)” column shown in the screenshot above from all list views of a document library called “Documents” in the site http://portal. Whilst I have focused in this article on removing columns generated by unused workflows, you can use exactly the same script to remove columns from any list or document library.


About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 Workflow. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s