Powershell -command "& {C:\MyScript.ps1 | out-file x:\Results.txt}"
The output in the file looks as follows...
=========================================
Stopped Services on Exchange 2007 Servers
=========================================
Server : ServerName
ServicesNotRunning : {MSExchangeSearch, MSFTESQL-Exchange}
=========================================
Stopped Services on Exchange 2003 Servers
=========================================
Server Name State
------ ---- -----
Server1 MSExchangeMGMT Stopped
Server2 MSExchangeMTA Stopped
Server3 MSExchangeMGMT Stopped
All nicely formatted when you open the text file. But it looks like this
when I use Get-Content command.
=========================================Stopped Services on Exchange 2007
Servers=========================================Server :
ServerName ServicesNotRunning : {MSExchangeSearch,
MSFTESQL-Exchange}=========================================
Stopped Services on Exchange 2003
Servers=========================================Server Name
State ------ ---- ----- Server1 MSExchangeMGMT Stopped
Server2 MSExchangeMTA Stopped Server3 MSExchangeMGMT Stopped
So, anyone know how do I keep the formatting in the body of the email?
Thanks in advance.
What does the file look like if you open it in Notepad?
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
It looks fine in notepad. In fact, the way it displays in Notepad is exactly
how I would like it to appear in the body of the email.
- Larry
Don Pedro wrote:
> It looks fine in notepad. In fact, the way it displays in Notepad is exactly
> how I would like it to appear in the body of the email.
>
> "RichS [MVP]" wrote:
>> It looks like you don't have new line markers on the end of some of your
>> lines which is causing Get-Content to treat them as single lines.
>> What does the file look like if you open it in Notepad?
"Don Pedro" <DonP...@discussions.microsoft.com> wrote in message
news:3D737A64-6C57-408D...@microsoft.com...
I use $msg.Body = Get-Content "x:\MorningChecksResults.txt"
As I said, opening the file in Notepad it displays very well and so I have
just attached it. But I would prefer to have no attachment and simply have
the results appear in the email body as they appear in the text file - nicely
formatted.
Peter
"Larry__Weiss" wrote:
> .
>
try
$msg.Body = (Get-Content "x:\MorningChecksResults.txt" | Out-String)
The discussion in that webpage of how Get-Content interacts in a pipeline is
interesting.
An array of strings is bound to $msg by this code
PS C:> $msg = Get-Content "Results.txt"
PS C:> $msg[0]
=========================================
PS C:> $msg[1]
Stopped Services on Exchange 2007 Servers
PS C:> $msg[2]
=========================================
PS C:> $msg[-2]
Server2 MSExchangeMTA Stopped
PS C:> $msg[-1]
Server3 MSExchangeMGMT Stopped
An array of characters with embedded line delineation
is bound to $msg by using this code
PS C:> $msg = (Get-Content "Results.txt" | Out-String)
PS C:> $msg[0]
=
PS C:> $msg[1]
=
PS C:> $msg[2]
=
PS C:> ("0x{0:x}" -f [int][char] $msg[-2])
0xd
PS C:> ("0x{0:x}" -f [int][char] $msg[-1])
0xa
- Larry
Larry__Weiss wrote:
> Using an idea from
> http://www.powershellcommunity.org/Forums/tabid/54/aff/1/aft/3514/afv/topic/afpgj/1/Default.aspx
>
> try
>
> $msg.Body = (Get-Content "x:\MorningChecksResults.txt" | Out-String)
>
> The discussion in that webpage of how Get-Content interacts in a
> pipeline is interesting.
>
>
> Don Pedro wrote:
>> Hi Larry,
>> I use $msg.Body = Get-Content "x:\MorningChecksResults.txt"
>> As I said, opening the file in Notepad it displays very well and so I
>> have just attached it. But I would prefer to have no attachment and
>> simply have the results appear in the email body as they appear in the
>> text file - nicely formatted.
>> Peter
>>
>> "Larry__Weiss" wrote:
>>> How are you inserting it into email?
>>>
Larry was spot on.
"John Vottero" wrote:
> .
>
Nicely formatted now...
"Larry__Weiss" wrote:
> .
>
- Larry