2015-10-27 71 views
-1

我有一個腳本,每兩小時運行一次以查看文件是否已被刪除。如果它在那裏,我會收到警報。我想更進一步,在移動文件時運行一項工作。到目前爲止,這裏是我有:如果文件存在,發送電子郵件並運行批處理腳本

$path  = "\\0.0.0.0\files\test\state\WAITING\*" 
$fileexists = Test-Path $path 
if ($fileexists) { 
    Send-MailMessage ` 
    -From [email protected] ` 
    -To [email protected] ` 
    -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 [email protected] ` 
     -To [email protected] ` 
     -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 
    } 
+0

那麼......問題是什麼? –

+0

您應該考慮使用PS本機cmdlet來移動文件,而不是編寫批處理文件。 'Get-Help移動*' – Xalorous

回答

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 [email protected] -To [email protected] -Subject "Files Have Arrived" -Body "The files have arrived and are being moved to the processing folder." -SmtpServer 0.0.0.2` 
} else { 
#donothing 
    } 
0

您可以使用分號「;」分開命令。

相關問題