How can I add a page heading in the following sample Powershell script?

I want to add a general heading to the output file, such as Purchase Orders.  
The following script needs to be modified to show Purchase Orders on the very top:

PowerShell script:

$InputFile = "C:\Source\source.txt"
$OutputFile = "C:\Output\changed.txt"


Function ParseText ($OutputFile,$InputFile){
Begin{
 $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
 Set-Content $OutputFile $null
 $Data = Get-Content -Path $InputFile | ?{$_ -match "(BEG\*)|(PO1\*)|(PID\*)|(SE\*)|N1"}
 }
 Process{
  $Data | % {
  #Check the end of data set
  If ($_ -match "N1"){
    $strArray = $_.split("*")
    $currString = $strArray[2] -replace '\s+', ' '
    $splitString = $currString.split(" ")
    $stringCnt = $splitString.count - 1
    $i = 0
    for ($i = 0; $i -le $stringCnt - 1; $i++)
    {
        $companyName += $splitString[$i] + " "
    }
    if ($companyName -ne $null)
    {
        $companyName = $companyName.TrimEnd()
        $companyID = $splitString[$stringCnt]
        $companyOut = "Company Shipto: " + $companyName + " " + $companyID
        $companyOut | out-file $OutputFile -Encoding UTF8 -Append
        $companyName = $null
    }
  }
  If ($_ -match "SE\*"){
    If($poline -ne $null -and $total -ne $null){
     $Totline = "Total: `$$Total"
     Write-host "This is Total `$$total"
     #Write the data collection to output file
     "$poline$line`r`n$totline`r`n" | out-file $OutputFile -Encoding UTF8 -Append
     #reset the variables
     $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
     }
  }
  #Collect the PO Number
  If($_ -match "BEG\*" -and $_ -match "\*(\w{2}\*)(\d{3,10})"){
     $poline = "PO Number: $($Matches[2])"
  }
  #Collect details
  If($_ -match "PO1\*{1,}\d\*(\d{1,})\*\w{1,}\*(\d{1,}(\.\d{1,})?).*\*(\d{1,})~"){
     $count = $Matches[1]
             $Price = $Matches[2]
             $UPC = $Matches[4]
             $total += [double]$count * [double]$Matches[2]
  }
  If($_ -match "PID\*"){
      $i++
      $Desc = $_ -Replace "PID\*\w\*{1,}(\d+\*{1,})?|<NL>|~"
      $line += "`r`nItem $i`: UPC: $UPC, Desc: $Desc, Qty: $count Price  `$$Price"
     }
   }
  }
 }

 If(Test-Path $InputFile){
  ParseText $OutputFile $InputFile
 }


The output data should look something like this:

PURCHASE ORDERS:

Company Shipto:  COMPANY DEST NAME              0123
PO Number: 0012-1234567-0234
Item 1: UPC: 123456712345, Desc: DESC, Qty: 5 Price  $1.00
Item 2: UPC: 234567891234, Desc: DESC 2, Qty: 3 Price  $2.00
Total: $11


Company Shipto: COMPANY DEST NAME              0345
PO Number: 0013-1234567-0567
Item 1: UPC: 123456712678, Desc: DESC, Qty: 5 Price  $3.00
Item 2: UPC: 234567896802, Desc: DESC 2, Qty: 3 Price  $4.00
Total: $27
100questionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven CarnahanNetwork ManagerCommented:
Try after:

#Write the data collection to output file

Place:

 Add-Content $OutputFile "Purchase Orders:`r`n`r`n"
Mauro CazabonnetSenior .NET Software EngineerCommented:
$InputFile = "C:\test\source.txt"
$OutputFile = "C:\test\changed.txt"


Function ParseText ($OutputFile,$InputFile){
Begin{
 $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
 Set-Content $OutputFile $null
 $Header = "Purchase Orders`r`n"
 $Header | Out-File $OutputFile -Encoding ASCII 
 $Data = Get-Content -Path $InputFile | ?{$_ -match "(BEG\*)|(PO1\*)|(PID\*)|(SE\*)|N1"}
 }
 Process{
  $Data | % {
  #Check the end of data set
  If ($_ -match "N1"){
    $strArray = $_.split("*")
    $currString = $strArray[2] -replace '\s+', ' '
    $splitString = $currString.split(" ")
    $stringCnt = $splitString.count - 1
    $i = 0
    for ($i = 0; $i -le $stringCnt - 1; $i++)
    {
        $companyName += $splitString[$i] + " "
    }
    if ($companyName -ne $null)
    {
        $companyName = $companyName.TrimEnd()
        $companyID = $splitString[$stringCnt]
        $companyOut = "Company Shipto: " + $companyName + " " + $companyID
        $companyOut | out-file $OutputFile -Encoding UTF8 -Append
        $companyName = $null
    }
  }
  If ($_ -match "SE\*"){
    If($poline -ne $null -and $total -ne $null){
     $Totline = "Total: `$$Total"
     Write-host "This is Total `$$total"
     #Write the data collection to output file
     "$poline$line`r`n$totline`r`n" | out-file $OutputFile -Encoding UTF8 -Append
     #reset the variables
     $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
     }
  }
  #Collect the PO Number
  If($_ -match "BEG\*") {  
     $strArray = $_.split("*")
     $currpo = $strArray[3]
     $poline = "PO Number: $currpo"
  }
  #Collect details
  If($_ -match "PO1\*{1,}\d\*(\d{1,})\*\w{1,}\*(\d{1,}(\.\d{1,})?).*\*(\d{1,})~"){
     $count = $Matches[1]
		 $Price = $Matches[2]
		 $UPC = $Matches[4]
		 $total += [double]$count * [double]$Matches[2]
  }
  If($_ -match "PID\*"){
      $i++
      $Desc = $_ -Replace "PID\*\w\*{1,}(\d+\*{1,})?|<NL>|~"
      $line += "`r`nItem $i`: UPC: $UPC, Desc: $Desc, Qty: $count Price  `$$Price"
     }
   }
  }
 }
 
 If(Test-Path $InputFile){
  ParseText $OutputFile $InputFile
 }
 
 

Open in new window

Mauro CazabonnetSenior .NET Software EngineerCommented:
Function ParseText ($OutputFile,$InputFile){
Begin{
 $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
 Set-Content $OutputFile $null
 $Header = "Purchase Orders`r`n"
 $Header | Out-File $OutputFile -Encoding ASCII 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
100questionsAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.