Hi @ZietZa
You could try to use the following code:
for(i=2022; i<2026; i++){
$FileRelativeURL1 = "/" + i + "/January/"+ i + "-January.xls"
$FileRelativeURL2 = "/" + i + "/February/"+ i + "-February.xls"
Download-FileFromLibrary -SourceFile $FileRelativeURL1
Download-FileFromLibrary -SourceFile $FileRelativeURL2
}
Function Download-FileFromLibrary()
{
param
(
[Parameter(Mandatory=$true)] [string] $SourceFile
)
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$SourceFile = "/sites/Marketing/Shared Documents" + $SourceFile
$DownloadPath ="C:\Temp"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#powershell download file from sharepoint online
Get-PnPFile -Url $SourceFile -Path $DownloadPath -AsFile
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
You could change the start year and end year according to your actual need.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.