Format Text Files from Get-Content

I have a project @ work where I am converting .MSG file s into Text files and then concatenating files into 1 text file, so it can be searched easily

The text file has a lot of extra spaces . Is there any way to format it so each email is easily identifiable

Here’s what I have so far

$outfile =  c:\SearchableFile.txt 
$files = (dir *.txt)
$files | %{
$_.FullName | `
Add-Content $outfile
Get-Content $_.FullName | Add-Content $outfile
}

The one file is being produced Id like to add some structure to it removing the spaces , and maybe creating a visible beginning and ending of each text file | email message. Something like this

Add-Content -Path c:\SearchableFile.txt  -Value "***************************************************************************************************"
Add-Content -Path c:\SearchableFile.txt  -Value "Start Of Message"
Add-Content -Path  c:\SearchableFile.txt  -Value "***************************************************************************************************"
Add-Content -Path c:\SearchableFile.txt  -Value ""

Add-Content -Path c:\SearchableFile.txt  -Value $Msg
    
Add-Content -Path c:\SearchableFile.txt  -Value ""
Add-Content -Path c:\SearchableFile.txt  -Value "***************************************************************************************************"
Add-Content -Path c:\SearchableFile.txt  -Value "EndOf Message"
Add-Content -Path c:\SearchableFile.txt  -Value "***************************************************************************************************"

Thank you

Do you have some example content? Without seeing an example, it’s going to be difficult for anyone to help.

Seconding Rob Simmons, if you show us an example of one of the files, we can help you out.

They where .msg files taht where converted to txt files .

so heres one

From:	Lou Claudio
Sent:	Tuesday, December 2, 2014 9:37 AM
To:	Andrew Boginson
Subject:	Phone Extension

Annie,

My says open 6739

Please replace 

Thank you,


Lou Angela 
Billing Coordinator 
Attorney Support Department 
561-555-1212 x6731 Office 
lclaudio@toyrrus.com | www.toysrus.com 


Supervisory Contact 
Erik Hannan 
561-555-1212 x6673 
ehannan@toysrus.com 

Pursuant to the Fair Debt Collection Practices Act, you are advised that this office may be deemed a debt collector and any information obtained may be used for that purpose. 

This email, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify me at 561- and permanently delete the original and any copy of any e-mail and any printout thereof.

Herb Anderson
Field Support Technician III
561-555-1212 Office
halexander@toysrus.com | www.toysrus.com 



This email, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify me at 561-and permanently delete the original and any copy of any e-mail and any printout thereof. 

so something that would begin/end the prior starting from the from:

i figured it out

$Files = Get-ChildItem -Path "C:\Users\jdoe\test1" -File *.txt
ForEach($File in $Files){
$Directory = 'C:\Testing\E\'
$path = $File.FullName 
$name = $file.name
$newname = "$($Directory)$($name)"
@(gc  $path) -match '\S'  | out-file $newname

foreach ($name in $newname){
$LogPath = 'c:\MasterEmail.txt'
Add-Content -Path $LogPath -Value "***************************************************************************************************"
Add-Content -Path $LogPath -Value "Start Of Email : $name"
Add-Content -Path $LogPath -Value "***************************************************************************************************"
Add-Content -Path $LogPath -Value ""

Add-Content -Path $LogPath -Value (gc $name)
    
Add-Content -Path $LogPath -Value ""
Add-Content -Path $LogPath -Value "***************************************************************************************************"
Add-Content -Path $LogPath -Value "End of Email"
Add-Content -Path $LogPath -Value "***************************************************************************************************"
}
}