0

我编写了一个 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、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

4

0 回答 0