Я хочу загрузить все файлы с точки обмена и нашел полезный ресурс: https://social.technet.microsoft.com/Forums/en-US/7b8a27f9-ae0e-443e-a4a4-8c1cb2ee3429/downloading-files-in-sharepoint-online-powershell?forum=sharepointdevelopment, следуя инструкциям
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$userName = "myemail@web.com"
$siteCollectionUrl = "https://web.sharepoint.com"
$webUrl = $siteCollectionUrl + "/sites"
$docLibraryTitle = "Application"
$destinationLocalFolder = "C:\test"
#------------------------------------------------
Import-Module C:\SPOMod\SPOMod20160326.psm1
#------------------------------------------------
Connect-SPOCSOM -Username $userName -Url $webUrl
#Download document function
function HTTPDownloadFile ($serverFileLocation, $downloadPath)
{
#create secure password
$sPassword = $password | ConvertTo-SecureString -AsPlainText -Force
$webClient = New-Object System.Net.WebClient
$webClient.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $sPassword)
$webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
[System.Uri]$destinationUri = [System.Uri]$serverFileLocation
Write-Host "Downloading" $serverFileLocation "as" $downloadPath
$webClient.DownloadFile($destinationUri, $DownloadPath)
$webClient.Dispose()
}
#------------------------------------------------
#Get files (not dirs)
$listItems = Get-SPOListItems -ListTitle $docLibraryTitle -IncludeAllProperties $true -Recursive | where {$_.FsObjType -eq 0}
#Iteration on all files in doc. library
foreach ($item in $listItems)
{
[string]$sourceDirectory = $item.FileDirRef
[string]$sourceFileName = $item.FileLeafRef
[String]$sourceFileUrl = $siteCollectionUrl + $item.FileRef
#create destination directory
[string]$destinationDirectory = $destinationLocalFolder + $sourceDirectory
$destinationDirectory = $destinationDirectory.Replace("/","\")
if (!(Test-Path -path $destinationDirectory))
{
New-Item -path $destinationDirectory -type directory
}
#download current version document
[string]$destinationFilePath = $destinationDirectory + "\" + $sourceFileName
HTTPDownloadFile $sourceFileUrl $destinationFilePath
}
Скрипт находит все файлы, но при попытке загрузки: ошибка :
Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (401) Unauthorized."
At C:\Users\SHAREPOINT.ps1:28 char:5
+ $webClient.DownloadFile($destinationUri, $DownloadPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Пожалуйста, помогите.