试图在Powershell脚本中执行.bat

时间:2015-07-06 12:52:17

标签: powershell

尝试执行以下脚本,其中我给出了“代码不工作”的注释我想将日志写入logfile。  正在运行的代码不是将日志写入日志文件

#run email bat file
Write-Host "Running email bat file...... \n"
  #below comand working 
Start-process run.bat -workingdirectory "D:\EmailConnector-Disc Optimus"

 #below code not working 
 Start-Process "cmd" -ArgumentList '/c','D:\EmailConnector-Disc Optimus\run.bat', 'connector.log' -WorkingDirectory "D:\EmailConnector-Disc Optimus\logs"

 ### tried below code as well but no luck 
   &'D:\EmailConnector-Disc Optimus\run.bat' >$emailconnecter_log
    Write-Host $rc

    if (-not $?) 
    { 
    Write-Host $rc
        $status = "running Daily email bat file failed on $hostname";
        Del_Daily
        Del_Dat
    #   Send_Mail
        exit
    }
    else
    {
    Write-Host $rc
    Write-Host "Email send sucess fully....."
    }

感谢您的回复。

1 个答案:

答案 0 :(得分:0)

我不会使用.bat而是使用Powershell发送它,

send-mailmessage -to "Remote <Someome@place.gov>" -from "Sender <Sender@Place.gov>" -subject "Print Spooler has Stopped" -SmtpServer place.gov

因为你已经在其余部分使用了PowerShell。