$logpath = "c:\logs\"
$importeditems = Get-ChildItem -Path "c:\ftp\foo\" -Recurse
$outpath = "c:\ftp\bar\"
function writelog ($message,$path){
$time = get-date -Format "yyyyMMdd:HHmm"
$line = $time + " | $message" | Out-File -FilePath $($path + "log.txt") -Append -Encoding utf8
}
if ($importeditems){
writelog -message "New files found doing some stuff." -path $logpath
foreach ($item in $importeditems){
#starta något annat eller vad du tänkt att göra mer filerna...
Move-Item -Path $item.PSPath -Destination $($outpath + $item.name)
writelog -message $("Done with stuff, file is moved to " + $($outpath + $item.name)) -path $logpath
}
}else{
#smtp skicka mail kanske? "Nattimport fungerar inte"
writelog -message $("ALERT! No new files." + $($outpath + $item.name)) -path $logpath
}