I wrote a powershell script to upload files that are created in a local folder to SharePoint with Add-PnPFile.
I loop the script every 20 seconds to check the folder for new files and then upload if the file is not on SharePoint yet. I use a Where-object to select only the last 5 minutes to not have to much files in the loop. (it needs to upload fast since flow is ERP->Local folder-> SharePoint and users are waiting)
This works like 95% of the time but sometimes it skips a files that is existing.
$Localfolder = "D:\DATA"
$A_Files = Get-ChildItem -Path $Localfolder -Include @("*.pdf", "*.csv") | Where-Object {$_.LastWriteTime -gt (Get-Date).AddMinutes(-5)}
If I stop the script and run in the same Powershell session, it doesn't show the file. If I open another powershell session and run the command it shows the file.
Anyone know if there is caching or I'm missing something?
PS C:\Users\rob_admin> $PSVersionTable
Name Value
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Get-ChildItem -Path $Localfolder -Include @("*.pdf", "*.csv")by itself, without the filter? - mklement0