You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Get-PnPPage获取Web部件Section返回非整数,如何获取正确整数值?

获取PnP PowerShell中Web部件的正确Section整数值

当你使用Get-PnPPage获取页面Web部件时,输出列表里的Section列是整数序号,但直接访问Web部件对象的Section.order会得到小数——这是因为order是SharePoint内部用于小节布局排序的权重值,并非页面上显示的整数序号。

要获取正确的整数Section序号,可通过以下步骤实现:

  1. 获取目标页面对象

    $page = Get-PnPPage -Identity "你的页面名称或URL"
    
  2. 定位目标Web部件
    假设你已通过$webparts2 = $page.Controls获取所有Web部件,取第6个(索引5)Web部件:

    $targetWebPart = $webparts2[5]
    
  3. 匹配对应的Section并计算序号
    通过页面的Sections集合找到包含该Web部件的小节,再通过集合索引计算整数序号(索引从0开始,需加1):

    # 找到包含目标Web部件的Section
    $matchingSection = $page.Sections | Where-Object { $_.WebParts -contains $targetWebPart }
    # 计算整数Section序号
    $sectionNumber = ($page.Sections.IndexOf($matchingSection)) + 1
    

执行后,$sectionNumber就是和Get-PnPPage输出列表中一致的整数Section值。

内容的提问来源于stack exchange,提问作者H Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:26:11