Powershell工作流程

时间:2017-11-24 03:53:49

标签: powershell powershell-workflow

我编写了一个PowerShell工作流程,用于分析Excel数据并根据Excel中的值触发邮件。

我开发了一个触发邮件的工作流程,但我在分析Excel数据方面遇到了麻烦,我无法调用Send-Mail工作流程。

注意:列“E-remainder 1”和“F-remainder 2”包含要发送的剩余邮件的日期。

Workflow test {
    $worksheet = InlineScript {
        $objExcel = New-Object -ComObject Excel.Application
        $objExcel.Visible = $false
        $WorkBook = $objExcel.Workbooks.Open(#filepath)
        $worksheet = $workbook.Sheets.Item(#sheetname)
        $currentdate = (Get-Date).ToString()

        $rownumber = #contains rownumber from excel whose details has to be mailed

        foreach ($i in $rownumbers) {
            if ($worksheet.Range("B$i").Text -eq $currentdate) {
                $output = [PSCustomObject][ordered]@{
                    ComputerName = $WorkSheet.Range("C$i").Text
                    Fromaddress = $WorkSheet.Range("D$i").Text
                    Toaddress = $WorkSheet.Range("E$i").Text
                }
                # I need to call a workflow which sends a mail
                # (workflow which I have to trigger mail)
                Send-Mail -To $output.Toaddress -From $output.Fromaddress -Name $output.ComputerName
            } elseif ($worksheet.Range("F$i").Text -eq $currentdate) {
                $output = [pscustomobject][ordered]@{
                    ComputerName = $WorkSheet.Range("C$i").Text
                    Fromaddress = $WorkSheet.Range("D$i").Text
                    Toaddress = $WorkSheet.Range("E$i").Text
                }
                # I need to call a workflow which sends a mail
                # (Based on my knowledge I know that we couldn't call a workflow inside the inline script)
                Send-Mail -To $output.Toaddress -From $output.Fromaddress -Name $output.ComputerName
            }
        } # foreach ends
    } # Inline ends
} # workflow ends

我收到以下错误:

  

错误:术语" Send-Mail"不被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

0 个答案:

没有答案