$dateToday = Get-Date $dateYesterday = $dateToday.AddDays(-1) $logfile = "D:\IFSBOSystem\Log\DCP_Mover.log" Set-Location ("D:\IFSBOData\FSV\Incoming\DCP_ud\{0:d4}\{1:d2}" -f $dateYesterday.Year, $dateYesterday.Month) $dateToday.ToString('[yyyy-MM-dd HH:mm:ss] ') | Out-File -FilePath $logfile -NoNewline -Append "------ New run starting ------" | Out-File -FilePath $logfile -Append $files = Get-ChildItem * -Recurse | Where-Object { $_.Attributes -notmatch 'Directory' } | Where-Object { $_.Directory -notmatch ("IFSBOData\\FSV\\Incoming\\DCP_ud\\{0:d4}\\{1:d2}\\{2:d2}" -f $dateToday.Year, $dateToday.Month, $dateToday.Day) } $destination = 'D:\IFSBOData\FSV\Incoming\DCP_ud' foreach($file in $files) { $dateToday.ToString('[yyyy-MM-dd HH:mm:ss] ') | Out-File -FilePath $logfile -NoNewline -Append "Moving '$($file.FullName)' to '$destination'" | Out-File -FilePath $logfile -Append $file | Move-Item -Destination $destination } $dateToday.ToString('[yyyy-MM-dd HH:mm:ss] ') | Out-File -FilePath $logfile -NoNewline -Append "------ Run ended ------" | Out-File -FilePath $logfile -Append