Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to deal with word wrapping in Get-Content

Status
Not open for further replies.

58sniper

MIS
Apr 25, 2004
9,152
US
I'm using this code to capture all activity in a PoSh session and email it to myself. It works great, except that the content of the file ends up as one long word wrapped line in the body of the email.

Code:
$logfolder = "C:\Temp\"
$logname = Get-Date -f "MM-dd-yyyy hh-mm-ss P"   
$emaillogname = Get-Date -f "MM-dd-yyyy hh:mm:ssp"   
$logpath = $logfolder + $logname + "M.txt"

function Begin-Transcript	{
    if(Test-Path $logfolder)
    {
    Start-Transcript $logpath -append -force
    }
}

function Email-Transcript	{
    $message = New-Object System.Net.Mail.MailMessage
    $message.From = "administrator@contoso.com"
    $message.To.Add("pat@contoso.com")
    $message.Subject = "PowerShell Transcript $emaillogname" + "m"

    $smtp = New-Object System.net.Mail.SmtpClient
    $smtp.Host = "sh-email2.contoso.local"   
    $smtp.UseDefaultCredentials = $true
    $smtp.Send($message)
}


function Bye	{
    Stop-Transcript
    Email-Transcript
    Remove-Item    $logpath   
    exit
}

Begin-Transcript

I've verified that the text file is correctly formatted. It's only when it's inserted into the body of the email that it wraps. This renders is pretty much impossible.

Has anyone had this issue before, and found a way around it?

Pat Richard MVP

Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.

 
Maybe I am missing something here but I don't see you actually using $message.body.

Have you tried using HTML?
Code:
$mailmessage.IsBodyHtml = 1

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top