![](/img/trans.png)
[英]Trying to upload files to subfolder in Sharepoint Online via Powershell
[英]How to list the files in a sharepoint online directory via powershell
您好,我正在尝试通过 PowerShell 将文件上传到我的 Sharepoint 站点(根目录)。 我可以连接到 url 但在尝试上传我已安装的文件时遇到问题 Install-Module SharePointPnPPowerShellOnline
当我运行命令时出现此错误
Add-PnPFile :远程服务器返回错误:(403) Forbidden。 在 line:1 char:1 + Add-PnPFile -Path D:\\delme\\test.xlsx -Folder / + ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Add-PnPFile], WebException +fullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.AddFile
添加-PnPFile -Path D:\\delme\\test.xlsx -Folder /
我知道我很接近。
使用下面的 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"
嗨您可以使用此代码上传文件并检查文件是否成功更新
代码 -
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" } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.