您好,我正在尝试通过PowerShell将文件上传到我的Sharepoint网站(根目录)。 我可以连接到网址,但是在尝试上传文件时遇到问题 我已经安装了Install-Module SharePointPnPPowerShellOnline
当我运行命令时出现此错误
Add-PnPFile:远程服务器返回错误:(403)禁止。 在第1行:char:1 + Add-PnPFile-路径D:\ delme \ test.xlsx-文件夹/ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:WriteError :( :) [Add-PnPFile],WebException + FullyQualifiedErrorId:EXCEPTION,SharePointPnP.PowerShell.Commands.Files.AddFile
Add-PnPFile -D:\ delme \ test.xlsx-文件夹/
我知道我已经接近了。
答案 0 :(得分:0)
使用下面的PowerShell。
$siteurl="https://ABC123.sharepoint.com/sites/XXX/teamsites/os"
Connect-PnPOnline -Url $siteurl
Add-PnPFile -Path D:\delme\test.xlsx -Folder "Directory and Operating Systems"
答案 1 :(得分:0)
嗨,您可以使用此代码上传文件并检查文件是否成功更新
代码 -
Import-Module SharePointPnPPowerShellOnline
#Get Connection to the url via Connect-PnPOnline $URL
Connect-PnPOnline "Some SharePoint Url" -UseWebLogin
#store all the files in the folder(get files using get-ChildItem)
#for single file you can use something like : $file = LocalPath\fileName.txt
$Files = Get-ChildItem "Local Folder Path which contains the files"
#Looping through each item
foreach($File in $Files){
#storing the add-pnpFile in a variable so that i will be able to know the status, if my file have been successfully uploaded or not.
#"Shared Documents\If inside shared document you want to give some folder it will come here" else only "Shared Document"
$upload = Add-PnPFile -Folder "Shared Documents\FolderToUpload" -Path $File.FullName
#now checking, if file successfully uploaded or not and printing the required message. (You can use Write-Host $message if you want to print the message)
if($upload.UniqueId){
$message = "Successfully Uploaded"
}
else {
$message = "ERROR - Unable to Upload"
}
}