[英]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: 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
I am getting 'access denied':我收到“拒绝访问”:
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
I'm probably doing something wrong or didn't make the proper settings.我可能做错了什么或没有进行正确的设置。 Can you please help me?
你能帮我么? Thanks in advance.
提前致谢。
looks like you connect fine, but not allowed to upload, so looks like permission issues on your app creation, make sure to go to https://mydomain.sharepoint.com/_layouts/15/appinv.aspx (if you want to upload to main site, normally you would want to upload to sub sites, but just using your example) On that page type the “Client ID” that you got when you created the app into the “App ID” field and then click the “Lookup” button Add the following into Permission Request XML:看起来你连接正常,但不允许上传,所以看起来你的应用程序创建权限问题,请确保 go 到https://mydomain.Z2D60FC67EF31D40B76705037DA990/iflayouts/5到上传到主站点,通常您希望上传到子站点,但仅使用您的示例)在该页面上,将创建应用程序时获得的“客户端 ID”键入“应用程序 ID”字段,然后单击“查找” 按钮 在权限请求 XML 中添加以下内容:
Then click create at the bottom Click "Trust It" to set permissions and try again
然后点击底部的创建点击“信任”设置权限再试一次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.