Connect SharePoint Web Parts programatically with PowerShell

Markus Kolbeck
Markus' Blog
Published in
2 min readNov 15, 2017

With PowerShell, you can easily add Web Parts to a SharePoint WebPart Page.
Using the SharePointPnP.PowerShell Commands this can be done using the CmdLet Add-PnPWebPartToWebPartPage.

I added a “Query String (URL) Filter” (QueryStringFilterWebPart) Web Part and multiple “List Viewer” (XsltListViewWebPart) Web Parts to a Web Part Page and needed to set up the (filter) connections.
This can be done manually using the web interface, but I wanted to automate this step using PowerShell as well.

Here is an example on how to connect two Web Parts (a “Query String (URL) Filter” Web Part and a “List Viewer” Web Part) using PowerShell.

I was inspired by the blog post Add Custom Web Parts to a page and Connect them using PowerShell from Isha Jain. Thanks for sharing!

For your “ProviderFieldNames” you need to add the “Filter Name” of the Query String URL Filter Web Part property.

Query String (URL) Filter Web Part Properties

If you run the above script multiple times, multiple Web Part Connections (duplicates) will be created. Therefore, I recommend to delete all Web Part Connections before creating them.

Here is an example for that.

If you want to query the existing Web Part connections, use the following code snippets.

Unfortunately I have not discovered any way to connect SharePoint Web Parts using the pnp PowerShell framework or any other CSOM approach, yet.

--

--