DebbieCoates_IPL
Programmer
I have a PowerShell script that copies excel files received within the last 10 minutes from one location to another, However, the last file in each folder is still in use, so when it copies them to the destination, the file is corrupt and wont open. So I need to amend my script to put all all but the last file received in the last 10 minutes, or filter out locked files. Any idea's or pointers would be appreciated, this is my script
$StartDate = (Get-Date).Addminutes(-10)
$EndDate = Get-Date
$StrSource ="filesystem::\\ipl\dfs\SecureFTP\Rospen-Yield"
$StrTarget= "filesystem::\\ipl\dfs\Shares\KPI Team\Secure\Backing Data\Data Uploads\Test"
Get-ChildItem $StrSource -filter "Report_B*.xlsx" -Recurse | Where-Object {($_.LastWriteTime.Date -ge $StartDate.Date) -and ($_.LastWriteTime.Date -le $EndDate.Date)} | Copy-Item -Destination $StrTarget
$StartDate = (Get-Date).Addminutes(-10)
$EndDate = Get-Date
$StrSource ="filesystem::\\ipl\dfs\SecureFTP\Rospen-Yield"
$StrTarget= "filesystem::\\ipl\dfs\Shares\KPI Team\Secure\Backing Data\Data Uploads\Test"
Get-ChildItem $StrSource -filter "Report_B*.xlsx" -Recurse | Where-Object {($_.LastWriteTime.Date -ge $StartDate.Date) -and ($_.LastWriteTime.Date -le $EndDate.Date)} | Copy-Item -Destination $StrTarget