【问题标题】:How to upload a file to a hub site in SharePoint Online using PowerShell如何使用 PowerShell 将文件上传到 SharePoint Online 中的中心网站
【发布时间】:2021-12-29 08:58:05
【问题描述】:

我创建了一个新应用,生成了应用 ID 和密码,为 https://mydomain.sharepoint.com 分配了完全权限,但我无法使用以下 PowerShell 命令将文件上传到共享文档文件夹:

$SharePointURL = "https://mydomain.sharepoint.com"
$SharePointDestPath = "/Shared Documents"
$file = "some-file"

Connect-PnPOnline -Url $SharePointURL -ClientId "asddsf-9999-4a88-8c79-ab8cabc67889" -ClientSecret "123343sdsfsdgfg2343434345656=" -WarningAction Ignore
Write-Host "done"
Write-Host "Uploading output file ... " -NoNewline
Add-PnPFile -Path $file -Folder $SharePointDestPath
Disconnect-PnPOnline

我收到“拒绝访问”:

PS E:\sharepoint_online> .\script.ps1
Connecting to SharePoint online ... done
Uploading output file ... Add-PnPFile : Access denied.
At E:\sharepoint_online\script.ps1:26 char:1
+ Add-PnPFile -Path $file -Folder $SharePointDestPath -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPFile], ServerUnauthorizedAccessException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.AddFile

我可能做错了什么或没有进行正确的设置。你能帮我么 ?提前致谢。

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    您的连接似乎正常,但不允许上传。您的应用创建似乎存在权限问题。请转至https://mydomain.sharepoint.com/_layouts/15/appinv.aspx 进行验证(如果您想上传到主站点,通常您会想要上传到子站点,但只是使用您的示例) 在该页面上,将创建应用程序时获得的“客户端 ID”键入“应用程序 ID”字段,然后单击“查找”按钮 在权限请求 XML 中添加以下内容:

    <AppPermissionRequests AllowAppOnlyPolicy="true">
      <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
    </AppPermissionRequests>
    

    然后点击页面右下角的创建。在下一页单击“信任”以设置权限并重试。

    【讨论】:

    • 请修正语法(尤其是标点符号)并用代码块替换图像。
    猜你喜欢
    • 2016-04-29
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2021-09-25
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多