【发布时间】:2015-09-28 17:03:44
【问题描述】:
我发现了一个很棒的脚本。我要做的唯一更改是仅列出文件,而不是新文件夹。此脚本应监视文件夹和子文件夹,并仅在创建新文件时通知。如何将其过滤为仅文件?我可以在 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
}
谢谢
【问题讨论】:
标签: file powershell notifications monitoring