de-DEen-GB
 
rss

Just can't get enough of IT

This blog is about mostly anything in IT. But the primary focuses are Microsoft Technologies like Exchange, Office 365, Azure and Cloud Security.
On December 16, 2016
0 Comment
297 Views

When migrating Html content from a CMS database or other sources you might find the Html as an Html encoded string.

Example:

<p><strong>Some Text</strong></p>

But you want to have the string look like this:

<p><strong>Some Text</strong></p>

Script

The following script is a simple PowerShell script to convert an exisiting file containing the Html encoded text and save the decoded string to a new output file.

param(
 [string]$InputFile,
 [string]$OutputFile
)
Add-Type -AssemblyName System.Web

Write-Output "Fetching $($InputFile)"

$fileContent = Get-Content $InputFile

Write-Output "Converting"

[System.Web.HttpUtility]::HtmlDecode($fileContent) | Out-File -FilePath $OutputFile -Encoding utf8 -Force

 

Usage

.\Convert-ToHtml.ps1 -InputFile '.\InputFile.txt' -OutputFile '.\Output.html'

 

Enjoy!

 

Read More »
On April 22, 2016
0 Comment
1130 Views

The PowerShell script Get-Diskspace.ps1 uses a pretty basic inline CSS approach to generate a more nicely html email from a PowerShell output.

You can use the following description for your own PowerShell script.

First a new html block is configured and the inline CSS is embedded into the head tag.

# Some CSS to get a pretty report
# Variable containing the inline CSS and the full html head tag
$head = @'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html><head><title>$($ReportTitle)</title>
<style type=”text/css”>
<!–
body {
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
h2{ clear: both; font-size: 100%;color:#354B5E; }
h3{
    clear: both;
    font-size: 75%;
    margin-left: 20px;
    margin-top: 30px;
    color:#475F77;
}
table{
    border-collapse: collapse;
    border: none;
    font: 10pt Verdana, Geneva, Arial, Helvetica, sans-serif;
    color: black;
    margin-bottom: 10px;
}
 
table td{
    font-size: 12px;
    padding-left: 0px;
    padding-right: 20px;
    text-align: left;
}
 
table th {
    font-size: 12px;
    font-weight: bold;
    padding-left: 0px;
    padding-right: 20px;
    text-align: left;
}
->
</style>
'@

The recurring data content is added to a global varibale using the -Fragment attribute. This ensures that no full html document data is being created.

$global:Html += $wmi | ConvertTo-Html -Fragment -PreContent "<h2>Server $($ServerName)</h2>"

Before sending the html result the full body html is generated by combinding the html fragments and the manually defined html head.

[string]$Body = ConvertTo-Html -Body $global:Html -Title "Status" -Head $head

Send-Mail -From $MailFrom -To $MailTo -SmtpServer $MailServer -MessageBody $Body -Subject $ReportTitle  

Enjoy.

Read More »