簡體   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