SOLVED

Get column position of webpart modern SharePoint page

%3CLINGO-SUB%20id%3D%22lingo-sub-1029683%22%20slang%3D%22en-US%22%3EGet%20column%20position%20of%20webpart%20modern%20SharePoint%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1029683%22%20slang%3D%22en-US%22%3E%3CP%3EWho%20could%20help%20me%3F%20For%20some%20good%20reason%20I%20have%20to%20get%20the%20column%20and%20section%20of%20an%20existing%20webpart%20that%20I%20want%20to%20use%20later%20in%20my%20Powershell%20script.%20Now%20I%20can%20easily%20get%20the%20section%20and%20use%20it%20again.%20But%20I%20cannot%20get%20the%20column%20as%20a%20variable.%20I%20already%20tried%20it%20as%20you%20see%20below%20with%20a%20substring%20or%20a%20split.%20But%20I%20noticed%20that%20different%20results%20came%20back%20at%20different%20sites.%20So%20again%2C%20who%20knows%20the%20solution%20for%20me%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1029683%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%20PowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%20Modern%20UI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1030252%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20column%20position%20of%20webpart%20modern%20SharePoint%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1030252%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F260040%22%20target%3D%22_blank%22%3E%40jorikpolhuis%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20you%20have%20a%20webpart%20in%20a%20page%20and%20you%20want%20to%20know%20its%20section%2C%20position%20and%20column%2C%20right%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20mean%2C%20using%20the%20PnP-PowerShell%20I%20figured%20the%20best%20way%20would%20be%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C!--%20StartFragment%20%20--%3E%3C%2FP%3E%3CDIV%3E%3CSPAN%3E%24homePage%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3EGet-PnPClientSidePage%3C%2FSPAN%3E%20%3CSPAN%3E-Identity%3C%2FSPAN%3E%3CSPAN%3E%20Home.aspx%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3E%3C!--%20StartFragment%20%20--%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CDIV%3E%3CSPAN%3E%24webPart%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E%24homePage%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EControls%3C%2FSPAN%3E%3CSPAN%3E%20%7C%20%3C%2FSPAN%3E%3CSPAN%3EWhere%3C%2FSPAN%3E%3CSPAN%3E%20Title%20%3C%2FSPAN%3E%3CSPAN%3E-eq%3C%2FSPAN%3E%26nbsp%3B%3CWEBPARTTITLE%3E%3C%2FWEBPARTTITLE%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Ethe%20%24webPart%20variable%20will%20have%20all%20the%20elements%20you're%20looking%20for%2C%20I%20think.%20Let%20me%20know%20if%20you%20still%20have%20questions%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3ERegards%3C%2FDIV%3E%3CSPAN%3E%3C!--%20EndFragment%20%20--%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CP%3E%3C!--%20EndFragment%20%20--%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1030389%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20column%20position%20of%20webpart%20modern%20SharePoint%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1030389%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F365643%22%20target%3D%22_blank%22%3E%40Carlos_Marins%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20quick%20reply!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20thought%20the%20same%2C%20but%20if%20i%20do%20%24webpart.column%20i%20get%20another%20table%20with%20content.%3C%2FP%3E%3CP%3EIn%20this%20content%20there%20is%20no%20column%20available.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F158764i9C575A3130F1BFEF%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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 (Occasional 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!