none
How to convert enhanced rich text field to plain text field using a powershell script RRS feed

  • Question

  • We need to convert all the rich text fields in a site collection to plain text field.

    I am using the below powershell script to convert the rich text field to plain text field, however it is not working for enhanced rich text field

    if ((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null) {
      Add-PSSnapin 'Microsoft.SharePoint.PowerShell'
    }
    CLS
    $spAssignment = Start-SPAssignment
    # Get All Web Applications
    $WebApps=Get-SPWebApplication https://<site>
    foreach($webApp in $WebApps) {
        # Get All  Site Collections in the Web Application
        Write-Host 'Web Application:' $($webApp.URL)
        foreach ($spSite in $webApp.Sites) {
    		
            if($spSite.URL -eq 'https://<site>/Projects/RC1')
    		{
    			Write-Host 'Site Collection:' $($spSite.URL)
    			
    			# Get the SubSites/Webs in the Site Collection
    			foreach($spWeb in $SPsite.AllWebs) {
    				# Get the the Lists in the Web
    				 
    				Write-Host 'SP Web URL' $($spweb.URL)
    				foreach($list in $spWeb.Lists) {
    					# Get the the Dcuments/List Items in the list
    					Write-Host 'List Title' $($list.Title)
    					foreach($field in $list.Fields)
    					{
    						if($field.RichText -eq $True)
    						{
    							$field.RichText = $False
    							#Set Field Type to 'Plain Text'
    							$field.RichTextMode = 'Compatible'
    							$field.Update()
    							Write-Host 'Field Type Updated Successfully!' $($field.Title)
    						}
    						if($field.RichTextMode -eq 'FullHtml')
    						{
    							$field.RichText = $False
    							#Set Field Type to 'Plain Text'
    							$field.RichTextMode = 'Compatible'
    							$field.Update()
    							Write-Host 'Field Type Updated Successfully!' $($field.Title)
    						}
    					}
    				}
    			}
    		}
        }
    }
    Stop-SPAssignment $spAssignment

    Below is the script output

    powershell output

    No change in the list for the field that is enhanced rich text

    No change in enhanced rich text field


    Prabinesh

    Tuesday, November 3, 2020 1:58 PM

All replies

  • The error is telling you that you cannot modify the structure of a collection using a loop as the loop input will get changes inside the loop and invalidate the collection being looped over.  This is a common issue with attempts to alter the keys of a collection.  It is not possible to use this method so you must get all keys into an array then use the keys to access the collection.  This will bypass the reordering and re-allocation of the collection inside of the loop.


    \_(ツ)_/

    Tuesday, November 3, 2020 4:36 PM