Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Powershell脚本邮件发送到EmailAddress的错误消息_Email_Powershell_Send_Mailmessage - Fatal编程技术网

从Powershell脚本邮件发送到EmailAddress的错误消息

从Powershell脚本邮件发送到EmailAddress的错误消息,email,powershell,send,mailmessage,Email,Powershell,Send,Mailmessage,我为Salesforce中的Dataloader构建了一个脚本: **# The Function for the Check Error File** function CheckErrorFile { Param ([string]$perrorfilepath) $csvlines = (Get-Content $perrorfilepath | Measure-Object -line).Lines # header is always 1

我为Salesforce中的Dataloader构建了一个脚本:

   **# The Function for the Check Error File** 

    function CheckErrorFile {

    Param ([string]$perrorfilepath)

    $csvlines = (Get-Content $perrorfilepath | Measure-Object -line).Lines

    # header is always 1 row so we look for > 1 rows
    if ($csvlines -gt 1)
    {
        $errorCount = $csvLines - 1
        $errorMessage = [string]::Format("** errors ** {0} failed rows in {1}", $errorCount, $perrorfilepath)
        # this will print red error message but not stop execution
        write-error $errorMessage
    }

}

**# set up locations/variables for data loader**
$dataloader = "C:\Program Files (x86)\salesforce.com\Data Loader\bin\process.bat"
$dlconfig = "U:\Projekte\Salesforce\Dataloader-Test-Infor-Files\Example-Migration-SF-Test\DataLoaderConfig"
set-location  "C:\Program Files (x86)\salesforce.com\Data Loader\bin"
$dlLogFolder = "U:\Projekte\Salesforce\Dataloader-Test-Infor-Files\Example-Migration-SF-Test\Logs\" 
**# execute the data loader**

& $dataloader $dlconfig testsf-delete

**# check for errors in the error.csv file**
CheckErrorFile ("{0}error_testsf.csv" -f $dlLogFolder)
到目前为止还不错

但是我想说的是,CheckErrorFile命令返回的错误代码应该发送到一个电子邮件地址

所以我考虑了两个因素:

  • 如果发送到邮件时出错

  • 将错误输出打包到变量中并发送到邮件地址

  • 但我不太擅长Powershell,因此我知道如何将其集成到脚本中

    当事件日志发生更改时,我发现一个站点有一个发送触发器,但我不确定是否可以将其用于我的目的,以及如何将其集成:

    有人能帮忙吗


    thnks

    那么您只是在问如何在PowerShell中发送邮件?这里应该已经有很多这样的例子了。在你的函数中,我唯一要改变的是将
    写入错误
    更改为
    写入输出
    ,因为在一个标准流中捕获它会更容易。是的,我知道这些示例,但我不知道如何在我的脚本中实现它……看看这里的示例,你所要做的就是从中捕获正确的输出你的身体功能