Hi @manny juan ,
You can use following powershell script to download attachment file to loacal first
# link to the folder
$olFolderPath = "\\xxx@outlook.com\Inbox\MyAlerts"
# set the desired file name
$attachmentFileName = 'test.txt'
# set the location to temporary file
$filePath = "$ENV:Temp"
# use MAPI name space
$outlook = new-object -com outlook.application;
$mapi = $outlook.GetNameSpace("MAPI");
# set the Inbox folder id
$olDefaultFolderInbox = 6
$inbox = $mapi.GetDefaultFolder($olDefaultFolderInbox)
# access the target subfolder
$olTargetFolder = $inbox.Folders | Where-Object { $_.FolderPath -eq $olFolderPath }
# load emails
$emails = $olTargetFolder.Items
# process the emails
foreach ($email in $emails) {
# format the timestamp
$timestamp = $email.ReceivedTime.ToString("yyyyMMddhhmmss")
# filter out the attachments
$email.Attachments | Where-Object {$_.FileName -eq $attachmentFileName} | foreach {
# insert the timestamp into the file name
$fileName = $_.FileName
$fileName = $fileName.Insert($fileName.IndexOf('.'),$timestamp)
# save the attachment
$_.saveasfile((Join-Path $filePath $fileName))
}
}
Then you can upload local file to sharepoint library
#Variables
$SiteURL = "https://xxx.sharepoint.com/sites/xxx"
$FilesPath = "C:\Temp"
$ServerRelativePath = "/sites/retail/Shared Documents"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get All Files from a Local Folder
$Files = Get-ChildItem -Path $FilesPath -Force -Recurse
#bulk upload files to sharepoint online using powershell
ForEach ($File in $Files)
{
Write-host "Uploading $($File.Directory)\$($File.Name)"
#upload a file to sharepoint online using powershell - Upload File and Set Metadata
Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder $ServerRelativePath -Values @{"Title" = $($File.Name)}
}