Forum Discussion

Baron164's avatar
Baron164
Brass Contributor
Jan 10, 2023
Solved

Script to Convert fixed width txt to csv missing fields

Here is the script:       [cmdletbinding()] Param( [parameter(Mandatory=$true)][string]$Path ) function Get-ExportHeader([string]$Path) { if (Test-Path -Path $Path) { # Ch...
  • Baron164's avatar
    Jan 13, 2023

    I made the following change which appears to have resolved the issue.

                    for ($index = 0; $index -lt $Header.Count; $index++)
                {
                    if ($Header[$index].Position -ge $_.Length)
                    {
                        $HashTable.Add($Header[$index].Name, $null);
                    }
                    #elseif ($index -lt ($Header.Count - 1))
                    elseif ($Header[$index].Position + $Header[$index].Length -lt ($_.length))
                    {
                        $HashTable.Add($Header[$index].Name, $_.SubString($Header[$index].Position, $Header[$index].Length).Trim());
                    }
                    else
                    {
                        $HashTable.Add($Header[$index].Name, $_.SubString($Header[$index].Position).Trim());
                    }
                }

Resources