powershell - 我想在线上传本地文件夹的所有数据到Sharepoint的“General”文件夹
问题描述
请教我。我是初学者。我想将本地文件夹的所有数据上传到Sharepoint online(等)的“General”文件夹Folder A/files
中Folder A/Folder B/Folder C/files
。
此代码是四个参数错误。
$SubFolder = (($file.Directoryname).Replace($localFolder,'')).Replace('\','/')
[Microsoft.SharePoint.Client.File]::SaveBinaryDirect($script:context, $script:context.Url + "/" + $rootfolder.Name + "/" + $folderName + $SubFolder + "/" + $file.Name, $fs, $true)
$SubFolder
是 /A 等。
解决方案
function UploadDocuments(){
Param(
[ValidateScript({If(Test-Path $_){$true}else{Throw "Invalid path given: $_"}})]
$LocalFolderLocation,
[String]
$siteUrl,
[String]
$documentLibraryName
)
Process{
$path = $LocalFolderLocation.TrimEnd('\')
Write-Host "Provided Site :"$siteUrl -ForegroundColor Green
Write-Host "Provided Path :"$path -ForegroundColor Green
Write-Host "Provided Document Library name :"$documentLibraryName -ForegroundColor Green
try{
$credentials = Get-Credential
Connect-PnPOnline -Url $siteUrl -CreateDrive -Credentials $credentials
$file = Get-ChildItem -Path $LocalFolderLocation -Recurse
$i = 0;
Write-Host "Uploading documents to Site.." -ForegroundColor Cyan
(dir $path -Recurse) | %{
try{
$i++
if($_.GetType().Name -eq "FileInfo"){
$SPFolderName = $documentLibraryName + $_.DirectoryName.Substring($path.Length);
$status = "Uploading Files :'" + $_.Name + "' to Location :" + $SPFolderName
Write-Progress -activity "Uploading Documents.." -status $status -PercentComplete (($i / $file.length) * 100)
$te = Add-PnPFile -Path $_.FullName -Folder $SPFolderName
}
}
catch{
}
}
}
catch{
Write-Host $_.Exception.Message -ForegroundColor Red
}
}
}
UploadDocuments -LocalFolderLocation C:\Lee\Share -siteUrl https://domain.sharepoint.com/sites/Developer -documentLibraryName MyDOc4
推荐阅读
- javascript - 将两个 Promise 的结果输出到单个对象中
- java - Warnings when running my web app with Glassfish 4.1.1 in Netbeans
- angular - 如何正确设置新的 Angular 6 项目
- sql - 在 SQL Server 中一次性获取 DISTINCT COUNT
- javascript - 有没有办法暂停和恢复加载 JavaScript 的 html 元素?
- python - 如何获取注释变量以在 django 模板上显示数据?
- r - 只提取 _ 之后的字母,中间有数字
- c++ - 隐藏超出边界的 QGraphicsItem 区域
- php - 如何在本地 Web 系统上执行自我更新?
- responsive-design - Bootstrap4 响应式导航栏在调整大小时包装文本