通过PowerShell发送电子邮件

时间:2018-05-12 21:33:13

标签: powershell

变量$DATA10$DATA11已经提供了数据。

function email {
    $Dis = $DATA11|Where-Object As -EQ 'Gr'|Select-Object In
    $Dis.Count
    $Dis1 = $DATA10 |
            Where-Object As -EQ 'Gr'|
            Select-Object In
    $Dis1.Count
    if ($Dis.Count -gt 0) {
        $dis = (($Dis1.Count/$Dis.Count)*100)
        Write-Host "Percentag is:" + $dis
        Write-Host ""
    } else {
        Write-Host "No value"
    }
}

email
$email = email

当我尝试在电子邮件正文中获得上述此函数的输出时,我只得到整数值而不是Write-Host内容,它显示在解释器的输出屏幕中但不存储在变量中。 / p>

function global:Send-Email {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$False, Position=0)]
        [String]$Address = "guido@compperf.com",
        [Parameter(Mandatory=$False,Position=1)]
        [String]$Subject = "Swimming",
        [Parameter(Mandatory=$False)]
        $Body = $email
    )
    Begin {
        Clear-Host
        #Add-Type -assembly "Microsoft.Office.Interop.Outlook"
    }
    Process {
        # Create an instance Microsoft Outlook
        $Outlook = New-Object -ComObject Outlook.Application
        $Mail = $Outlook.CreateItem(0)
        $Mail.To = "$Address"
        $Mail.Subject = $Subject
        $Mail.Body = $Body
        $Mail.HTMLBody = $email
        #$File = "D:\CP\timetable.pdf"
        #$Mail.Attachments.Add($File)
        $Mail.Send()
    }
    End {
        # Section to prevent error message in Outlook
        $Outlook.Quit()
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook)
        $Outlook = $null
    }
}

Send-Email -Address vikram@hotmail.com -Body $email 

电子邮件正文的输出是

10 2

我期望的是在ISE中显示的那个:

10

2

Percentag is: 10

0 个答案:

没有答案