Я хочу загрузить все данные локальной папки в папку «Общие» онлайн-ресурса Sharepoint - PullRequest
0 голосов
/ 13 мая 2018

Пожалуйста, научи меня. Я начинающий. Я хочу загрузить все данные локальной папки в папку «Общие» онлайн-ресурса 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 is / A и т. Д.

1 Ответ

0 голосов
/ 14 мая 2018

Вы можете попробовать ниже скрипт здесь , руководство здесь .

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
...