简体   繁体   English

监控文件夹中的文件

[英]Monitoring files in folders

So my code works now by notifying me when files have not been added.所以我的代码现在可以通过在没有添加文件时通知我来工作。 My Problem now is that I have more customers and my foreach loop does not seem to work.我现在的问题是我有更多的客户,我的foreach循环似乎不起作用。 It still emails me 1 customer.它仍然给我发电子邮件 1 客户。

Here is my code:这是我的代码:

[string]$path = "X:\Brievenbus\Customer1"
[string]$path = "X:\Brievenbus\Customer2"

 $File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }


$SMTPMessage = @{
To = $To
From = $From
Subject = "$Subject at $Path"
Smtpserver = $SMTPServer
}

$Path | ForEach {$Path += $($_.FullName)
$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }
If ($File -eq $null)
{ $SMTPBody = "`nLaatste 24H is er niets meer gestuurd bij klant:`n`n     $($_.FullName) $path"

Send-MailMessage @SMTPMessage -Body $SMTPBody
}
}

Well, it depends on how much time you want to use and where the files are saved.嗯,这取决于您要使用多少时间以及文件的保存位置。 If it is a server, either Windows or Linux/Unix Windows PowerShell or PowerShell core on Linux/Unix could be used together with a scheduled task / cron job.如果是服务器,则 Windows 或 Linux/Unix Windows PowerShell 或 Linux/Unix 上的 PowerShell 核心都可以与计划任务/cron 作业一起使用。

You could set the job to run a script every x hours.您可以将作业设置为每 x 小时运行一个脚本。 Check the created or last edited date of each backup file and compare it to the current timestamp.检查每个备份文件的创建或上次编辑日期,并将其与当前时间戳进行比较。 If the files edit / create date is longer than your set limit, send an email, write a log or however you wish to handle it.如果文件编辑/创建日期超过您设置的限制,请发送电子邮件、写日志或您希望处理的任何方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM