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.
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.
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.