Sure! To download all files in a specified folder, you can use the Get-SPOFolder cmdlet to retrieve the files and then download them using Start-ThreadJob to create 3 parallel download threads.
Here's a script that demonstrates how to do this:
# Connect to SharePoint Online
Connect-SPOService -Url "https://[tenant]-admin.sharepoint.com" -Credential (Get-Credential)
# Specify the site and folder
$siteUrl = "https://[tenant].sharepoint.com/sites/[site]"
$folderRelativeUrl = "/[library]"
# Get the SPOFolder object
$folder = Get-SPOFolder -Url "$siteUrl$folderRelativeUrl"
# Get all files in the folder
$files = $folder.Files
# Define the download function
function Download-File {
param(
[Parameter(Mandatory=$true)]
[string]$fileUrl,
[Parameter(Mandatory=$true)]
[string]$outputPath
)
Invoke-WebRequest -Uri $fileUrl -OutFile $outputPath
}
# Define the jobs
$jobs = foreach ($file in $files) {
$fileUrl = $file.ServerRelativeUrl
$outputPath = "C:\path\to\save\$($file.Name)"
Start-ThreadJob -Name "Download-$($file.Name)" -ScriptBlock ${function:Download-File} -ArgumentList $fileUrl, $outputPath
}
# Wait for all jobs to complete
Wait-ThreadJob -Job $jobs
# Get the results
$results = Get-ThreadJob -Job $jobs
# Display the results
$results | ForEach-Object {
$file = $_.Name.Replace("Download-", "")
Write-Host ("Downloaded file {0} to {1}" -f $file, $_.Result)
}
Replace [tenant], [site], [library], and C:\path\to\save\ with actual values for your SharePoint Online tenant, site, library, and local save path.
This script uses Start-ThreadJob to create 3 parallel download threads. The Wait-ThreadJob cmdlet is used to wait for all jobs to complete before displaying the results. The Get-ThreadJob cmdlet is used to retrieve the results of the jobs, and the Write-Host cmdlet is used to display a message indicating that a file has been downloaded.
Keep in mind that downloading many large files in parallel may put significant load on your network and storage resources, so use this approach with caution. You can adjust the number of parallel threads by modifying the $jobs array.