2

I have some custom column created by office dev pnp template. It was visible initial. Then I set this column on hidden.

<Field ID="{1ada65e8-4f90-46c5-a663-a5812131215e}" Name="WorkspaceType" DisplayName="Workspace type" Type="Choice" Required="TRUE" Group="Valo" SourceID="{3647d1ac-79f7-474e-90ed-73078508a792}" StaticName="WorkspaceType" AllowDeletion="TRUE" EnforceUniqueValues="FALSE" Indexed="FALSE" FillInChoice="FALSE" Format="Dropdown" Hidden="TRUE" >
          <CHOICES>
            <CHOICE>Team</CHOICE>
            <CHOICE>Community</CHOICE>
            <CHOICE>Internal Project</CHOICE>
            <CHOICE>Proposal</CHOICE>
            <CHOICE>External Project</CHOICE>
          </CHOICES>
        </Field>

Now I would like to unhide this column. It is not working in office dev pnp template so I would like to do that in powershell. I try this but it is not working:

Connect-PnPOnline -Url http://myO365SiteCollection.com
$field = Get-PnPField -Identity WorkspaceType 
$field.Hidden = $False 
$field.Update()

$ctx = Get-PnPContext
$ctx.ExecuteQuery()

After this I go to site settings and go to columns. I still not see my column. I close the powershell window and open a new instance. I check what the value is of field.hidden property and it says it is true. So my change is not executed. What I am doing wrong. If someone know another solution how to unhide a column please let me know.

1

Not really sure why PnP powershell is not working as expected, but you can use CSOM with powershell to make it visible as below:

$User = "admin@tenant.onmicrosoft.com"
#enter site your collection url
$SiteURL = https://tenant.sharepoint.com/sites/site 


#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds

$fieldTitle = "WorkspaceType"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle) 
$customfield.Hidden = $false
$customfield.UpdateAndPushChanges($true)

$Context.ExecuteQuery()
| improve this answer | |
-2

I had the same problem, and solved it with the following line:

$field.Context.ExecuteQuery()

Instead of your original 2 lines:

$ctx = Get-PnPContext
$ctx.ExecuteQuery()
| improve this answer | |
  • This should probably be a comment on the original question since it doesn't solve the original problem by itself, just improves the code. – Graham Aug 9 '17 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.