请教我。我是初学者。
我想将本地文件夹的所有数据上传到" General" Sharepoint文件夹在线(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等。
答案 0 :(得分:0)
您可以在脚本here,guide here下面尝试。
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