Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Output to email not working

$
0
0

Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4

Hi All

This is whitespace report works as an email attachment but not as an email e.g. information in capacity.html not embedded in the email. I thought the $body=get-content ...would have work but obviously i am wrong, can anyone help

If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null)

{ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 }
$whitespace  = ".\capacity.htm"
$checkrep = Test-Path ".\capacity.htm"
If ($checkrep -like "True")
{ Remove-Item ".\capacity.htm"
}
New-Item ".\capacity.htm" -type file
$MessageParams = @{
From = 'abc@test.com'
To = "admin@test.com"
subject = "CAPACITY $((get-date).ToShortDateString())"
SMTPServer = 'smtpserver'
}
Add-Content $whitespace "<html>"
Add-Content $whitespace "<head>"
Add-Content $whitespace "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859 1'>"
Add-Content $whitespace '<title>Mailbox DB Capacity Management Report</title>'
add-content $whitespace '<STYLE TYPE="text/css">'
add-content $whitespace  "<!--"
add-content $whitespace  "td {"
add-content $whitespace  "font-family: Consolas;"
add-content $whitespace  "font-size: 12px;"
add-content $whitespace  "border: 1px solid #999999;" 
add-content $whitespace  "padding: 0px;border-collapse:collapse;" 
add-content $whitespace  "margin: 3px;"
add-content $whitespace  "}"
add-content $whitespace  "body {"
add-content $whitespace  "margin: 5px;" 
add-content $whitespace  "}"
add-content $whitespace  "table {"
add-content $whitespace  "border: thin solid #000000; padding:0px;"
add-content $whitespace  "}"
add-content $whitespace  "-->"
add-content $whitespace  "</style>"
Add-Content $whitespace  "</head>"
Add-Content $whitespace  "<body><p>Your info text</p>"
add-content $whitespace  "<table>"
Add-Content $whitespace "<tr bgcolor='BlanchedAlmond'>"
Add-Content $whitespace  "<td align='center'><B>DB Name</B></td>"
Add-Content $whitespace  "<td align='center'><B>Server</B></td>"
Add-Content $whitespace  "<td align='center'><B>DB Size(GB)</B></td>"
Add-Content $whitespace  "<td align='center'><B>WhiteSpace(GB)</B></td>"
Add-Content $whitespace  "<td align='center'><B>LastFullBackup</B></td>"
Add-Content $whitespace  "<td align='center'><B>LastIncrementalBackup</B></td>"
Add-Content $whitespace "</tr>"

$databases = Get-MailboxDatabase -Status | ?{$_.Recovery -ne "$True"} | sort -Descending DatabaseSize,
AvailableNewMailboxSpace
foreach($Database in $databases)
{  
         Write-Host $Database.Name `t $Database.Server `t $Database.DatabaseSize `t $Database.AvailableNewMailboxSpace -ForegroundColor Green
$currdate = ( Get-Date ).ToString('dd/MM/yyyy')       
         $ServerName = $Database.Server
                                $machineName = $Database.Name
                                 $dbsize = $Database.DatabaseSize.ToGB()
         $svcState = $Database.AvailableNewMailboxSpace.ToGB()
         $lstfull = $Database.LastFullBackup
        if ( $lstfull -eq $null){ $lstfull = "Alert!"}else{
            $lstfull = $lstfull.ToString('dd/MM/yyyy')
                 $lastFullBackup = $Database.LastFullBackup; $currentDate = Get-Date
                                   $howOldBkpFull = $currentDate - $lastFullBackup
                                   $howOldBkpFull = $howOldBkpFull.days         
          }                  
            if($howOldBkpFull -gt '7' -or $lstfull -eq "Alert!"){$bgfcolor = "purple"}else{$bgfcolor = ""}
         $lstinc = $Database.LastIncrementalBackup
        if ( $lstinc -eq $null){ $lstinc = "Alert!"}else{
            $lstinc = $lstinc.ToString('dd/MM/yyyy')
                                    $lastIncBackup = $Database.LastIncrementalBackup; $currentDate = Get-Date
                                    $howOldIncFull = $currentDate - $lastIncBackup
                                    $howOldIncFull = $howOldIncFull.days            
                                }
            if($howOldIncFull -gt '1' -or $lstinc -eq "Alert!"){$bgicolor = "purple"}else{$bgicolor = ""}
                                 $bgcolor = "white"
if($dbsize -gt '550' -and $svcState -lt '20'){$bgcolor = "yellow"}
if($dbsize -gt '600' -and $svcState -lt '15'){$bgcolor = "orange"}
if($dbsize -gt '650' -and $svcState -lt '10'){$bgcolor = "red"}
         Add-Content $whitespace "<tr bgcolor= '$bgcolor'>"
         Add-Content $whitespace "<td  align=center>$machineName</td>"
         Add-Content $whitespace "<td align=center>$ServerName</td>"
         Add-Content $whitespace "<td align=center>$dbsize</td>"
         Add-Content $whitespace "<td align=center>$svcState</td>"
         Add-Content $whitespace "<td bgcolor= '$bgfcolor' align=center>$lstfull</td>"
         Add-Content $whitespace "<td bgcolor= '$bgicolor' align=center>$lstinc</td>"
         Add-Content $whitespace "</tr>"
}

Add-content $whitespace  "</table>"
Add-Content $whitespace "</body>"
Add-Content $whitespace "</html>"
$body=get-content “capacity.htm”
Send-MailMessage @MessageParams -body $body -bodyashtml -Attachments .\capacity.htm -Priority high

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles