Files
powershell/Dennis_Scripts/DCP_Mover.ps1
2023-03-09 09:06:25 +01:00

24 lines
1.1 KiB
PowerShell

$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