question

RamseyDwayne-9426 avatar image
0 Votes"
RamseyDwayne-9426 asked sadomovalex answered

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

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.

windows-server-powershelloffice-sharepoint-server-development
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RamseyDwayne-9426

I am currently doing some research on this issue, will let you know as soon as possible.

0 Votes 0 ·
TongZhangMSFT-7548 avatar image
0 Votes"
TongZhangMSFT-7548 answered TongZhangMSFT-7548 commented

Hi @RamseyDwayne-9426

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.





· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

We are running SharePoint Enterprise edition, In our CA, there is not a menu item with the name "Manage services on server" under Application Management, but "Manage Service Applications". In it I see "Microsoft SharePoint Foundation Subscription Settings Service Application Proxy" under Subscription Settings Service

0 Votes 0 ·

Hi @RamseyDwayne-9426,

According to my research, please try to use RepresentedWebPartType property of ErrorWebpart. Please refer to this document: https://www.c-sharpcorner.com/blogs/representedwebparttype-or-errorwebpart-problem-in-sharepoint1

Hope it can help you .Thanks for your understanding and support.

Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered RamseyDwayne-9426 commented

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://docs.microsoft.com/en-us/powershell/module/sharepoint-server/get-spwebpartpack?view=sharepoint-server-ps

https://docs.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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think you missed the point. I already have several scripts that are similar to the one you provided, which reads the web parts on the page. The scripts return all the web parts on the page, but the issue is that all of the web parts have a title of ErrorWebPart. This is why I cannot find the correct web part I need to modify. This is the issue I am trying to resolve.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Rich, but the odd thing is that the web parts are being loaded on the page. I can see and edit the web parts in the UI, and review and change their properties, and even see the correct title! It is only when I try to capture that information programmatically with PowerShell that I see ErrorWebPart. I'm not sure if this is something related to PowerShell, my environment, or some odd bug. Perhaps I should enter a support ticket, but I was hoping someone on these forums knew the answer

0 Votes 0 ·

I'm assuming that when you "see" the string "ErrorWebPart" it's when you use the variable, and that you're referencing the variable expecting to get a string. The default behavior of the object stored in that variable is probably to return its object type as a string.

If you get a value of "ErrorWebPart" in your script have a look at its' type: $variable.gettype() AND whether or not the object in the variable has a "ToString" method $variable | gm * -f. If there's not a "ToString" method then it's going to be inherited from the parent object, which is probably "System.Object", and that inherited method is going to just return the name of the object.

If the object type is ErrorWebPart, get the value returned from $variable.ErrorMessage.

In other words, you need to do some investigation (a.k.a. debugging) to determine the cause of your problem.





0 Votes 0 ·
sadomovalex avatar image
0 Votes"
sadomovalex answered

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)


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.