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

如何一次性将文档模板上传至多个SharePoint库?

批量上传SharePoint Online库模板的可行方案

方法一:PnP PowerShell脚本(推荐)

这是适配65个站点规模的高效批量操作方式,无需手动逐个站点操作。

前置准备

  1. 安装PnP PowerShell模块:打开管理员权限的PowerShell,执行命令 Install-Module -Name PnP.PowerShell -Force -AllowClobber
  2. 将需要上传的模板文件(如Template.docx)放在本地固定路径(例:C:\SPTemplates\Template.docx)
  3. 整理所有目标站点的URL,每行一个保存为文本文件(例:C:\SPTemplates\SiteList.txt)

脚本示例

# 配置参数
$templateLocalPath = "C:\SPTemplates\Template.docx"
$siteListFile = "C:\SPTemplates\SiteList.txt"
$targetLibraryName = "目标库名称" # 替换为实际库名,若各站点库名不同,需改成读取CSV匹配对应关系

# 读取站点列表
$siteUrls = Get-Content $siteListFile

# 遍历处理每个站点
foreach ($url in $siteUrls) {
    try {
        # 连接目标站点
        Connect-PnPOnline -Url $url -Interactive

        # 获取目标库对象
        $library = Get-PnPList -Identity $targetLibraryName -ErrorAction Stop

        # 定位/创建库的Templates文件夹(模板默认存储路径)
        $templatesFolder = Get-PnPFolder -Url "$($library.RootFolder.ServerRelativeUrl)/Forms/Templates" -ErrorAction SilentlyContinue
        if (-not $templatesFolder) {
            $templatesFolder = New-PnPFolder -Name "Templates" -Folder "$($library.RootFolder.ServerRelativeUrl)/Forms"
        }

        # 上传模板文件并覆盖已存在的同名文件
        Add-PnPFile -Path $templateLocalPath -Folder $templatesFolder.ServerRelativeUrl -OverwriteIfExists

        # (可选)将该模板设为库的默认文档模板
        Set-PnPList -Identity $targetLibraryName -Values @{DocumentTemplateUrl = "$($templatesFolder.ServerRelativeUrl)/Template.docx"}

        Write-Host "模板已成功上传至站点:$url" -ForegroundColor Green
    }
    catch {
        Write-Host "处理站点$url失败:$($_.Exception.Message)" -ForegroundColor Red
    }
    finally {
        # 断开站点连接
        Disconnect-PnPOnline
    }
}

注意事项

  • 若各站点库名称不一致,需将站点URL与对应库名整理成CSV文件,修改脚本读取CSV实现匹配
  • 执行脚本时使用拥有所有目标站点库编辑权限的账号登录
  • 建议先选取1-2个站点测试脚本,确认无误后再批量执行

方法二:Power Automate(无代码方案)

适合不熟悉PowerShell的用户,步骤相对繁琐但无需编写代码:

  • 创建手动触发的云流
  • 添加「获取项目」动作,连接存储目标站点URL和库名的SharePoint列表
  • 添加「应用到每一个」循环,遍历所有站点记录
  • 循环内依次添加「连接到SharePoint站点」「上传文件」动作,将模板上传至对应库的Forms/Templates文件夹
  • (可选)添加「更新列表」动作,设置库的默认模板

注意事项

  • Power Automate有运行配额限制,需确保配额覆盖65个站点的操作量
  • 批量执行时可能存在延迟,需等待流执行完成

方法三:站点集推送(仅限同结构站点集)

若65个站点属于同一站点集且库结构完全统一,可尝试:

  • 在站点集根站点配置好库模板,通过站点集设置将模板推送到所有子站点的对应库中
  • 此方法局限性极大,仅适用于严格统一的站点架构

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 02:05:08