使用 Powershell(选项 1-使用 PnP.Powershell)将文件上传到 Sharepoint Online (Microsoft 365) [英] Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 1-Using PnP.Powershell)

查看:41
本文介绍了使用 Powershell(选项 1-使用 PnP.Powershell)将文件上传到 Sharepoint Online (Microsoft 365)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to upload a file into a Sharepoint Online (M365) library subfolder, but it keeps giving me errors. I have tried many scripts. This post is about using PnP.Powershell (I have posted questions about other scripts hoping someone can help me with any of them)

这是代码:

$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:myFoldermyFile.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 中授予此权限?授予它安全吗?

How do I grant this permission in M365? Is it safe to grant it?

谢谢

推荐答案

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

PnP PowerShell need to be granted some privileges on your tenant.

也许你可以试试

Register-PnPManagementShellAccess

参考:使用 PnP PowerShell 连接

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

I guess it's safe if you ensure you are on the official build and not a customized (hacked) one.

基本上,它将授予模块使用委托授权执行某些任务的权利.它的权限不会超过您的帐户.

Basically, it will grant the module the right to perform some task using a delegated authorization. It won't have more privileges than your account.

这篇关于使用 Powershell(选项 1-使用 PnP.Powershell)将文件上传到 Sharepoint Online (Microsoft 365)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆