【问题标题】:List just files in a Powershell script仅列出 Powershell 脚本中的文件
【发布时间】: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


    【解决方案1】:

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

    来自Get-ChildItem for FileSystem

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

    【讨论】:

      猜你喜欢
      • 2010-10-05
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      相关资源
      最近更新 更多