仅列出Powershell脚本中的文件

时间:2015-09-28 17:03:44

标签: file powershell notifications monitoring

我找到了一个很棒的脚本。我想要做的唯一更改是仅列出文件,而不是新文件夹。此脚本应监视文件夹和子文件夹,并仅在创建新文件时通知。如何将其过滤到文件?我可以在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

}

由于

1 个答案:

答案 0 :(得分:0)

要仅列出文件,您可以将-File参数传递给Get-ChildItem

来自Get-ChildItem for FileSystem

  

要仅获取文件,请使用File参数并省略Directory参数。