Variables $DATA10
and $DATA11
havd data already.
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
When I try to get this output of this function above in the email body I get only the integer value and not the Write-Host
content which shows in the output screen of the interpreter but not stored in the variable.
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
Output of the email body is
10 2
What I expect is like the one that displays in the ISE:
10 2 Percentag is: 10