繁体   English   中英

如何使用 PowerShell 在线将文件上传到 SharePoint 中的中心站点

[英]How to upload a file to a hub site in SharePoint Online using PowerShell

I've created a new app, generated app id and secret, assigned full permissions for https://mydomain.sharepoint.com but I can't upload a file to the Shared Documents folder using the following PowerShell commands:

$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

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

看起来你连接正常,但不允许上传,所以看起来你的应用程序创建权限问题,请确保 go 到https://mydomain.Z2D60FC67EF31D40B76705037DA990/iflayouts/5到上传到主站点,通常您希望上传到子站点,但仅使用您的示例)在该页面上,将创建应用程序时获得的“客户端 ID”键入“应用程序 ID”字段,然后单击“查找” 按钮 在权限请求 XML 中添加以下内容: 应用程序 然后点击底部的创建点击“信任”设置权限再试一次

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM