none
Powershell - how to unhide a hidden site column?

    Question

  • Hello,

    I have used the following script to hide a field from the user community. It needed to be both - invisible inside Sharepoint content types and within the DIP (Document Information Panel) within Office 2010.

    
    ## Reference to SharePoint DLL
    
    
    # Specify url of the sitecollection
    $hostheader = "http://workspace"
    
    $site=new-object Microsoft.SharePoint.SPSite($hostheader)
    $rootweb = $site.rootweb
    
    $column = $rootweb.fields.GetFieldByInternalName("AdditionalData")
    $column.required = $false
    $column.ShowInDisplayForm = $false
    $column.ShowInEditForm = $false
    
    $column.ReadOnlyField = $true
    $column.Update($true)

    The question is now.. how can I unhide this field again?

    The column's property hidden is set to true. I cannot directly set this property as it says that hidden "is a read only property".

    What do you propose?

    Sven

    Monday, January 27, 2014 8:16 PM

Answers

  • try this code, use the your column name....

    $field = $list.Fields.GetFieldByInternalName("MyColumn")
    $type = $field.GetType()
    $mi = $type.GetMethod("SetFieldBoolValue",
        [System.Reflection.BindingFlags]$([System.Reflection.BindingFlags]::NonPublic -bor
        [System.Reflection.BindingFlags]::Instance))
    $mi.Invoke($field, @("CanToggleHidden",$true))
    $field.Hidden=$false
    $field.Update()


    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

    • Marked as answer by Sven W Monday, January 27, 2014 10:57 PM
    Monday, January 27, 2014 10:28 PM
    Moderator

All replies

  • You should be able to set the ShowInDisplayForm and ShowInEditForm values to $true again. If you want users to be able to edit the value, you can also set ReadOnlyField to $false.

    Please mark my reply as helpful (the up arrow) if it was useful to you and please mark it an answer (the check box) if it answered your question! Thank you!


    Danny Jessee | MCPD - SharePoint Developer 2010 | MCTS - SharePoint 2010, Configuring
    Blog: http://dannyjessee.com/blog | Twitter: @dannyjessee

    Monday, January 27, 2014 9:37 PM
  • I set the property .ReadOnlyField back to $false. However, implicitly the property .hidden was set to $true. It still does not show up. The properties ShowInDisplayForm and ShowInEditForm are set to $true.

    When I try to set the .hidden property to $false this happens:

    Exception setting "Hidden": Cannot change Hidden attribute for this field

    Monday, January 27, 2014 9:57 PM
  • I assume you called Update() again after making these changes?

    Please mark my reply as helpful (the up arrow) if it was useful to you and please mark it an answer (the check box) if it answered your question! Thank you!


    Danny Jessee | MCPD - SharePoint Developer 2010 | MCTS - SharePoint 2010, Configuring
    Blog: http://dannyjessee.com/blog | Twitter: @dannyjessee

    Monday, January 27, 2014 10:01 PM
  • Hi Sven,

    Hope this blog helps you to resolve the issue -

    http://sadomovalex.blogspot.com/2012/01/avoid-cannot-change-hidden-attribute.html

    and see this link also

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.cantogglehidden.aspx

    and http://ayman-elhattab.blogspot.com/2009/05/readonly-hidden-and-sealed-fields.html

    Hope this helps!



    MCITP: SharePoint 2010 Administrator
    MCTS - MOSS 2007 Configuring, .NET 2.0
    | SharePoint Architect | Evangelist |
    http://www.sharepointdeveloper.in/
    http://ramakrishnaraja.blogspot.com/


    Monday, January 27, 2014 10:07 PM
  • try this code, use the your column name....

    $field = $list.Fields.GetFieldByInternalName("MyColumn")
    $type = $field.GetType()
    $mi = $type.GetMethod("SetFieldBoolValue",
        [System.Reflection.BindingFlags]$([System.Reflection.BindingFlags]::NonPublic -bor
        [System.Reflection.BindingFlags]::Instance))
    $mi.Invoke($field, @("CanToggleHidden",$true))
    $field.Hidden=$false
    $field.Update()


    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

    • Marked as answer by Sven W Monday, January 27, 2014 10:57 PM
    Monday, January 27, 2014 10:28 PM
    Moderator
  • Can this be done via the Client Object Model? I'm getting a null MethodInfo back..

    $bindingFlags = [Reflection.BindingFlags] "NonPublic,Instance"

    [System.Type] $type = $orderField.GetType()

    [Reflection.MethodInfo] $mdInfo = $type.GetMethod("SetFieldBoolValue", $bindingFlags)

    Tuesday, October 21, 2014 9:43 AM
  • Using Reflection as proposed in a few of the answers is an "unsupported" action. It's easy to change the property by updating the XML schema of the column:

    $currentXML = $field.SchemaXML
    
    #Remove the node if it exists, and add again
    $newXml = $currentXML.Replace('CanToggleHidden="FALSE"','');
    $newXml = $currentXML.Replace('Hidden="TRUE"', 'Hidden="FALSE" CanToggleHidden="TRUE"');
    
    $field.SchemaXML = $newXML
    $field.Update
    

    The same works also through the Client OM.

    Friday, September 18, 2015 4:19 PM
  • Using Reflection as proposed in a few of the answers is an "unsupported" action. It's easy to change the property by updating the XML schema of the column:

    $currentXML = $field.SchemaXML
    
    #Remove the node if it exists, and add again
    $newXml = $currentXML.Replace('CanToggleHidden="FALSE"','');
    $newXml = $currentXML.Replace('Hidden="TRUE"', 'Hidden="FALSE" CanToggleHidden="TRUE"');
    
    $field.SchemaXML = $newXML
    $field.Update

    The same works also through the Client OM.


    Can you please advice why using Reflection is an unsupported action? and what do you mean by unsupported ??
    Friday, December 1, 2017 12:00 PM
  • This is a good cmdlet. 

    Moreover, to change the hidden-property on the root-web, you can use the script like this:

    $SpSite = Get-SPSite("http://localhost/"); $SpWeb = $SPsite.OpenWeb(); write-host $SpWeb $field = $SpWeb.Fields.GetFieldByInternalName("VideoSetRenditionsInfo") $type = $field.GetType() $mi = $type.GetMethod("SetFieldBoolValue",

    $SpSite =  Get-SPSite("http://localhost/"); 
    $SpWeb = $SPsite.OpenWeb(); 
    write-host $SpWeb
    
    $field = $SpWeb.Fields.GetFieldByInternalName("VideoSetRenditionsInfo")
    $type = $field.GetType()
    $mi = $type.GetMethod("SetFieldBoolValue", [System.Reflection.BindingFlags]$([System.Reflection.BindingFlags]::NonPublic -bor  [System.Reflection.BindingFlags]::Instance))
    $mi.Invoke($field, @("CanToggleHidden",$true))
    $field.Hidden=$false
    $field.Update()

    [System.Reflection.BindingFlags]$([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance))

    $mi.Invoke($field, @("CanToggleHidden",$true)) $field.Hidden=$false $field.Update()


    Thursday, May 17, 2018 8:05 PM