Powershell script fix

Hi ,

EE experts helped on my question.

In columnB i have all lines of a txt file except first line.
The original txt file has line breaks,
The new csv file do not. It's just one long piece of text . Can you please advice whether we can fix it?

get-childitem 'C:\EE\FOLDER\' |
  ? { $_.PsIsContainer } | % {
    $folder = $_.FullName
    get-childitem $folder -Filter *.txt | % {
      $content=Get-Content $_.FullName
      $colA = $content | select -first 1
      $colB = $content | Select -Skip 1
      if ($colB[0].Length -lt 10 -and $colB[0] -match '\w+\.[XVI]+\.\d+')
         $colA += ' ' + $colB[0]
         $colB = $colB[(-$colB.Count+1)..-1]
      New-Object PsObject -Property @{
         ColumnA= $colA -replace 'AuthorName', ''
         ColumnB = $colB -join ' ' }
    } | export-csv "C:\EE\FOLDER\$(Split-Path -leaf $folder).csv" -NoTypeInformation -Encoding UTF8

Open in new window

Who is Participating?
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
Change line 15 to
         ColumnB = $colB -join '`n' }

Open in new window

to retain all carriage returns.
magentoAuthor Commented:

I tried the above but get the value instead .. I used backtip n

eg: Dr. Dominik Waldvogel`nRaub`n2012
magentoAuthor Commented:
Tried double quote and it seems working, let me check all files and let you know.

ColumnB = $colB -join "`n" }

Open in new window

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

magentoAuthor Commented:
Thanks for the pointer .
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Oh, sorry, of course you need to use double quotes instead of single quotes. Stupid beginner's mistake.
magentoAuthor Commented:
I am afraid , if you are beginner ..What am i ???
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I'm not a beginner for sure, but still making mistakes like one ;-). This is one "habit" I don't get out of my way.
magentoAuthor Commented:
I know for sure you are not a beginner . Getting rank of Prodigy is not possible without great skills. Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.