Share via

Why do all web parts in a site page show as ErrorWebPart when using Powershell

Ramsey, Dwayne 21 Reputation points
2022-05-13T21:14:59.17+00:00

When using PowerShell to try modifying web parts on a site page (SP 2013/2016), all web parts (CEWP, CQWP, List, etc...) read as ErrorWebPart. I read some really dated posts on this issue, but never found a good solution for PowerShell. I also read that I may not be able to do this in PowerShell, and I may have to do this with an OM custom solution? All I need to do is change the list a CQWP is pointing to, but I have hundreds of sites I need to perform this change on.

Microsoft 365 and Office | SharePoint Server | Development
Windows for business | Windows Server | User experience | PowerShell

4 answers

Sort by: Most helpful
  1. sadomovalex 3,636 Reputation points
    2022-06-03T14:20:42.617+00:00

    could you provide PowerShell script which you try to use? In general it is possible to manipulate SP web parts from PS and automate it for running on many sites (long time ago I did something like that as well e.g. PowerShell script for fixing urls inside Content editor and Image viewer web parts in Sharepoint)

    0 comments No comments

  2. Rich Matheisen 48,116 Reputation points
    2022-05-23T18:24:21.457+00:00

    I know next to nothing about SharePoint, but ErrorWebPart is, according to system.web.ui.webcontrols.webparts.errorwebpart, a class that has a property ("ErrorMessage") that might shed some light on why the webpart isn't being loaded. There's also a "RenderContents" method that will encode the message in a way the removes any potential "badness" from the message.


  3. Limitless Technology 40,101 Reputation points
    2022-05-23T07:56:19.863+00:00

    hi RamseyDwayne-9426,

    We can use the script below to get the web part working:-

    $wp = $webpartmanager.WebParts | Where { $_.Title -eq "Site Assets"}

    To change the List View web part view:-

    configuration parameters

    $WebURL="http :// sp2013"

    Get objects

    $web = Get-SPWeb $WebURL
    $list = $web.Lists["Site Assets"]
    $view = $list.Views["Test"]

    $page = $web.GetFile("SiteAssets/Forms/AllItems.aspx")
    $page.CheckOut()
    $WebPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

    Get the Web part

    $wp = $WebPartManager.WebParts | Where { $_.Title -eq "Site Assets"}

    Update Webpart Property

    [xml]$x = $wp.XmlDefinition
    $wp.View.SetViewXml($view.SchemaXml)
    $wp.View.Update()

    Save and Publish

    $WebPartManager.SaveChanges($wp)
    $page.CheckIn("updated Property")

    For more information and better assistance refer to following documentation:- https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/get-spwebpartpack?view=sharepoint-server-ps

    https://learn.microsoft.com/en-us/microsoft-365/community/working-with-modern-clientside-pages-using-pnp-powershell

    I hope this answer and resolve your issue, Accept answer if found helpful.

    Thank You


  4. Tong Zhang_MSFT 9,261 Reputation points
    2022-05-16T08:28:08.443+00:00

    Hi @Ramsey, Dwayne

    Based on my research and testing ,as a troubleshooting ,please check if you executed the PowerShell script on a SharePoint Server that has the Microsoft SharePoint Foundation Web Application service running.

    (Application Management >> Manage services on server >> Microsoft SharePoint Foundation Web Application)


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.