Hi dear community,
What I want to achieve? great question, I want to copy the lastest file that was uploded to a Path directory and then copy it towards another path location for reporting purposes,
the code I’m using to attemp accomplish this action is the next one:
$filterDate = (Get-Date).AddDays(-5).Date
$Files = Get-ChildItem -Path "C:\repo\scripts\Copy move files\source\*.*" -File -ErrorAction SilentlyContinue | Where-Object {$_.TimeCreated -ge $filterDate}
foreach($File in $Files){
Copy-Item -Destination "C:\repo\scripts\Copy move files\target\" $File.FullName
}
someone else also recomeded me to use the << Where-Object { $.LastWriteTime -ge $FindDate -and $.LastWriteTime -le $Finddate.adddays(1) } >> but I’m not sure how to implemted it or if will actually search the newest/latest files within a given directory that is my main goal for later move it towards a Sharepoint for reporting purposes