Hey All
Currently I have ran into a problem with the way my results are reading when sending email containing what was captured.
#Pull in email showing approvals
Function Global:Get-Email {
Param(
[String]$Folder = "InBox",
[String]$Test ="Subject",
[String]$Compare = "Group Access"
)
Process{
$Folder = $Folder
Add-Type -Assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -ComObject Outlook.Application
$Namespace = $Outlook.GetNameSpace("MAPI")
$NameSpace.Folders.Item(0)
$Email = $NameSpace.Folders.Item(1).Folders.Item($Folder).Items
Clear-Host
Write-Host "Trawling through Outlook, please wait ...."
$Email | Where-Object {$_.$Test -match $Compare} | Sort-Object -Property `
@{Expression = "Unread";Descending=$true}, `
@{Expression = "Subject";Descending=$true} `
| select subject | Out-String
$Output = $Email | Where-Object {$_.$Test -match $Compare} | Sort-Object -Property `
@{Expression = "Unread";Descending=$true}, `
@{Expression = "Subject";Descending=$true} `
| select subject | Out-String
Write-Host "Sending Email containing results"
Send-MailMessage -SmtpServer 'smtp.youremail.com' -To 'youremail@youremail.com' -From 'youremail@youremail.com' -Subject "Automated Approval Report" -Body "$Output" -BodyAsHtml -Priority High -ErrorAction Stop
} # End of main section 'Process'
}
Get-Email #-Compare false
Gives me this Output, which is correct, the email just reads wrong, explained below
Trawling through Outlook, please wait …
Subject
Group Access - Order# 0000000 has been APPROVED
Group Access - Order# 0000001 has been APPROVED
However the email that is sent looks like this:
Subject ------- Group Access - Order# 0000000 has been APPROVED Group Access - Order# 0000000 has been APPROVED
I would like it to look like this:
Group Access - Order# 0000000 has been APPROVED
Group Access - Order# 0000001 has been APPROVED