如果文件存在,请发送电子邮件并运行批处理脚本

时间:2015-10-27 23:17:40

标签: powershell batch-file

我有一个每两个小时运行一次的脚本,以查看文件是否已被删除。如果它在那里,我会收到警报。我想更进一步,运行一个工作移动文件。到目前为止,我所拥有的是:

$path       = "\\0.0.0.0\files\test\state\WAITING\*"
$fileexists = Test-Path $path   
if ($fileexists) {
  Send-MailMessage `
    -From noreply@email.com `
    -To tester@foo.com `
    -Subject "Files Have Arrived" `
    -Body "The files have arrived and are being moved to the processing folder." `
    -SmtpServer 0.0.0.1
} else {
  #donothing
}

我想在ifexists中使用它:

Start-Process "cmd.exe" "/c \\0.0.0.0\files\test\MOVE.bat"

会是这样的吗?

$path       = "\\0.0.0.0\files\test\state\WAITING\*"
    $fileexists = Test-Path $path   
    if ($fileexists) {
      Send-MailMessage `
        -From noreply@email.com `
        -To tester@foo.com `
        -Subject "Files Have Arrived" `
        -Body "The files have arrived and are being moved to the processing folder." `
        -SmtpServer 0.0.0.1
Start-Process "cmd.exe" "/c \\0.0.0.0\files\test\MOVE.bat
    } else {
      #donothing
    }

2 个答案:

答案 0 :(得分:0)

我弄清楚了

$path       = "\\0.0.0.0\files\test\state\WAITING\*"
$fileexists = Test-Path $path
if ($fileexists) {
Start-Process "cmd.exe" "/c \\0.0.0.1\files\test\MOVE.bat"` | Send-MailMessage -From noreply@test.com -To tester@foo.com -Subject "Files Have Arrived" -Body "The files have arrived and are being moved to the processing folder." -SmtpServer 0.0.0.2`
} else {
#donothing
    }

答案 1 :(得分:0)

你可以使用分号&#34 ;;"分开命令。