繁体   English   中英

使用 Powershell(选项 1 - 使用 PnP.Powershell)将文件上传到 Sharepoint Online (Microsoft 365)

[英]Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 1-Using PnP.Powershell)

我正在尝试将文件上传到 Sharepoint Online (M365) 库子文件夹中,但它一直给我错误。 我尝试了很多脚本。 这篇文章是关于使用 PnP.Powershell(我已经发布了有关其他脚本的问题,希望有人可以帮助我解决其中的任何一个问题)

这是代码:

$url="https://mydomain.sharepoint.com/sites/mysharepointsite/" 

$userID = "mail@foo.com"
$securePassword = ConvertTo-SecureString -String "myPaswword" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $userID, $securePassword

Install-Module -Name PnP.PowerShell
Connect-PnPOnline $url -Credentials $credentials

$files = Get-Item -Path "C:\myFolder\myFile.csv" -Force
foreach ($file in $files)
{
    Add-PnPFile -Folder "myLibraryname/subfolder"  -Path $file.FullName
    Write-Host $done.Name  "Uploaded into the Site" -BackgroundColor Green
}

它给了我这个错误

Connect-PnPOnline : AADSTS65001: 用户或管理员未同意使用 ID 为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”的名为“PnP Management Shell”的应用程序。 为此用户和资源发送交互式授权请求。

我如何在 M365 中授予此权限? 授予它安全吗?

谢谢

PnP PowerShell 需要被授予对租户的一些权限。

也许你可以试试

Register-PnPManagementShellAccess

参考:使用 PnP PowerShell 连接

我想如果您确保您使用的是官方版本而不是定制的(被黑客入侵的)版本,那是安全的。

基本上,它将授予模块使用委托授权执行某些任务的权利。 它不会比您的帐户拥有更多的权限。

暂无
暂无

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

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