我找到了一个很棒的脚本。我想要做的唯一更改是仅列出文件,而不是新文件夹。此脚本应监视文件夹和子文件夹,并仅在创建新文件时通知。如何将其过滤到文件?我可以在get-childitem上添加一个排除吗?
Param (
[string]$Path = "\\path\share",
[string]$SMTPServer = "smtp server",
[string]$From = "email",
[string]$To = "email",
[string]$Subject = "New File(s) Received on the FTP site"
)
$SMTPMessage = @{
To = $To
From = $From
Subject = "$Subject at $Path"
Smtpserver = $SMTPServer
}
$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge (Get-Date).Addminutes(-10) }
If ($File)
{ $SMTPBody = "`nTo view these new files, click the link(s) below:`n`n "
$File | ForEach { $SMTPBody += "$($_.FullName)`n" }
Send-MailMessage @SMTPMessage -Body $SMTPBody
}
由于
答案 0 :(得分:0)