SOLVED

Get column position of webpart modern SharePoint page

Copper Contributor

Who could help me? For some good reason I have to get the column and section of an existing webpart that I want to use later in my Powershell script. Now I can easily get the section and use it again. But I cannot get the column as a variable. I already tried it as you see below with a substring or a split. But I noticed that different results came back at different sites. So again, who knows the solution for me?

4 Replies

Hey @jorikpolhuis,

 

So, you have a webpart in a page and you want to know its section, position and column, right?

 

I mean, using the PnP-PowerShell I figured the best way would be as follows:

 

$homePage = Get-PnPClientSidePage -Identity Home.aspx
$webPart = $homePage.Controls | Where Title -eq <webpartTitle>
 
the $webPart variable will have all the elements you're looking for, I think. Let me know if you still have questions
 
Regards

@Carlos_Marins Thanks for the quick reply!

 

I thought the same, but if i do $webpart.column i get another table with content.

In this content there is no column available.

 

clipboard_image_0.png

best response confirmed by jorikpolhuis (Copper Contributor)
Solution

Hi @jorikpolhuis,

 

Oh, I see. You want to be able to store these in variables right? These values are stored in the object Position, contained in the spControlData attribute of the webpart. So if you access $webpart.spControlData.Position, you may find the following attributes:

 

ControlIndex: the order of the webpart in the section(called Position when shown in the terminal)

ZoneIndex: webpart Section

SectionIndex: webpart Column

 

I know, it is a bit confusing that the Section index actually stores the variable's column. But anyway, that's the way it works here. You can test it in your tenant to see if it makes sense.

 

Regards

You are the best! It's indeed confusing but now i have it working. Thanks for the quick answer!
1 best response

Accepted Solutions
best response confirmed by jorikpolhuis (Copper Contributor)
Solution

Hi @jorikpolhuis,

 

Oh, I see. You want to be able to store these in variables right? These values are stored in the object Position, contained in the spControlData attribute of the webpart. So if you access $webpart.spControlData.Position, you may find the following attributes:

 

ControlIndex: the order of the webpart in the section(called Position when shown in the terminal)

ZoneIndex: webpart Section

SectionIndex: webpart Column

 

I know, it is a bit confusing that the Section index actually stores the variable's column. But anyway, that's the way it works here. You can test it in your tenant to see if it makes sense.

 

Regards

View solution in original post