none
how to delete a site columns from pages library with power shell script? RRS feed

  • Question

  • Hi Team,

    I am working with deletion of site column from pages library as follows

    RemoveSiteColumn($sUrl,[string]$fieldName)
     {
        try{       
         write-host $sUrl   
         $web= Get-SPWeb -Identity $sUrl    
         $list = $web.Lists["pages"]
         write-host $list.Name
         $column= $list.Fields.GetFieldByInternalName($fieldName)   
          if($Column)
         {
           write-host "Deleting List column " + $fieldName +" in site " + $web.url + $list.Name -fore yellow       
            $Column.Hidden = $false
            $Column.ReadOnlyField = $false
            $Column.Allowdeletion = $true
            $Column.Delete()
            write-host "site column " $column.Title " deleted successfully from the list " $web.url ".......... Done !" -fore blue
       
        write-host "site column " $column.Title " deleted successfully from the list " $web.url | Out-File -Append ".\OutPutLog.txt"
           
       
         }
         else
         {
           Write-Host "No such Columns"


           "No such Columns" + $column.Title + $web.url | Out-File -Append ".\OutPutLog.txt"
         }
         $web.Dispose()
         }

      catch
      {
        $ErrorMessage = $_.Exception.Message
         write-host $ErrorMessage
     }

    but its deleting and showing in list columns and when I selected the column for view its showing error message column is deleted but this column is coming from one content type. I want to delete column from content type in one pages library only.

    please let me know how to delete the column from list and its content type permanently and I would like to add the column to list and its content type later.

    Please help me how to write this script

    Thanks


    Srinivas


    Saturday, January 7, 2017 7:16 AM

All replies

  • Hi

    please check this similar post

    https://social.technet.microsoft.com/Forums/office/en-US/acd00db5-9fec-444b-8fd6-1babab380d20/delete-sharepoint-site-columns-with-powershell-script?forum=sharepointadminprevious

    Let me know if you need more details


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Saturday, January 7, 2017 11:07 AM
  • Hi Srinivas,

    It tested it in my test environment, please check the steps as follows:

    1. Create a site column "SiteColumnA".

    2. Create a site content type "CustomPageCT".

    3. Add the site column into the new site content type.

    4. Add the site content type into "Pages" library.

    5. Run the Script below to delete the "SiteColumnA" column.

    $sUrl="http://sp13/sites/test1"
    $fieldName="SiteColumnA"
    $web= Get-SPWeb -Identity $sUrl     
    $list = $web.Lists["Pages"]
    write-host $list.Name
    $column= $list.Fields.GetFieldByInternalName($fieldName)    
    if($Column)
    {
    	write-host "Deleting List column " + $fieldName +" in site " + $web.url + $list.Name -fore yellow        
    	$Column.Hidden = $false
    	$Column.ReadOnlyField = $false
    	$Column.Allowdeletion = $true
    	$Column.Delete()
    	write-host "site column " $column.Title " deleted successfully from the list " $web.url ".......... Done !" -fore blue
    	write-host "site column " $column.Title " deleted successfully from the list " $web.url | Out-File -Append ".\OutPutLog.txt"
    }

    If your issue still exists, please provide more details about how to reproduce this issue, others would get easier to research on it.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, January 9, 2017 8:45 AM
    Moderator
  • Thanks Denis for your reply  and I have followed this article 

    https://gallery.technet.microsoft.com/office/RemoveDelete-a-fieldcolumn-46e65f5b

    Regards,



    Srinivas

    Tuesday, January 10, 2017 12:43 PM
  • Hi Srinivas,

    Do you solve this issue?

    If the replies help you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, January 11, 2017 1:25 AM
    Moderator