Text file processing (read/write) using Powershell
<p>I have a text file with n number of records and each records contains two columns with delimited by tab. I am reading this text file and performing some mapping on the second column using the Powershell scripting. I am able to perform read the text file and able to perform mapping. But when i write the results using set-content command, i am getting below result.</p>

<p><strong>Input File:</strong></p>

<p>4803    6000000</p>

<p>4802    6000000</p>

<p>4803    6000000</p>

<p>4803    5000000</p>

<p><strong>Output File:</strong></p>

<p>@{Column1=4803; Column2=5000000;}</p>

<p>@{Column1=4802; Column2=6000000;}</p>

<p>@{Column1=4803; Column2=5000000;}</p>

<p>@{Column1=4803; Column2=5000000;}</p>

<p>I am not sure why i am getting Column name in each record. I don't want to see the result like this @{Column1=4803; Column2=5000000;} . But it should be like this - 4803    5000000.  Please could you help me to remove the special character and column names in the output file.</p>

<p><strong>Expected Result:</strong></p>

<p>4803    5000000</p>

<p>4802    6000000</p>

<p>4803    5000000</p>

<p>4803    5000000</p>

<p>Script:</p>

<pre><code>$fields = Get-Content Temp.txt
$results = @()
foreach($i in $fields)
{
    $field  = $i -split '\t' -replace '^\s*|\s*$'
    $field1 = $field[0]
    $field2 = $field[1]
    if ($field1 -eq "4803" -and $field[2].substring(0,2) -eq "60")
        {
            $field2 = "5000000"
        }
    else
        {
            $field2 = $field[1]
        }
            $details = @{       
                    Column1     = $field1
                    Column2     = $field2
                }
        $results += New-Object PSObject -Property $details 
    }
   $results | Select-Object Column1, Column2 | Set-Content -path Temp.txt    [Environment]::Exit(0)
</code></pre>