PowerShell to convert Ulster CSV to HomeBank

Asked by Julien Vailles

Hi, it is not question but more sharing a script I created in Powershell to convert Ulster Bank (Ireland) CSV to HomeBank. I saw the python script but well it is a different option. I just thought it could be useful to other.

Function Convert-UlsterCSVToHomeBankFormat{
<#
.SYNOPSIS
    Convert an UlsterBank CSV file to a HomeBank format.
.DESCRIPTION
 1. Download the CSV from your bank
 2. Copy it to the $Path folder, e.g. C:\CSV
 3. Call the function Convert-UlsterCSVToHomeBankFormat
 4. it will create the supported HomeBank format with *HomeBank.csv, use this file to import in HomeBank.
#>

    Try{
        $Path = 'C:\CSV' #Copy your Ulster CSV downloaded
        $PathToArchive = "$Path\Archived"
        if (!(Test-Path $PathToArchive)){New-Item -Path $PathToArchive -ItemType Directory}
        $Files = Get-ChildItem -Path $Path -File | Where-Object {$_.Name -notlike "*HomeBank.csv"}
        $Files|ForEach-Object{
            $File = $_.FullName
            Write-Host "Process $file to make it ready to import with HomeBank"
            #remove empty lines, remove the space before and after the header
            get-content $File | ? {$_.trim() -ne "" } | set-content "$($File)_rdy.txt"
            $CSV = import-csv "$($File)_rdy.txt" -Delimiter ","
            $CSV | ForEach-Object{
                $data1 = '0'
                $data2 = ''
                $data3 = 'Tag'

                $_ |
                Add-Member -MemberType NoteProperty -Name Payment -Value $data1 -PassThru |
                Add-Member -MemberType NoteProperty -Name Empty -Value $data2 -PassThru |
                Add-Member -MemberType NoteProperty -Name Tag -Value $data3 -PassThru

            }

            #$CSV |Select-Object Date,ColumnA |Export-Csv -Delimiter ";" -Path D:\new.csv -NoTypeInformation
            $CSV |Select-Object Date,Payment,Enpty,Description,Type,Value,Empty,Tag|export-csv "$($File)_HomeBank.csv" -NoTypeInformation -Delimiter ';'
        }
        #We move the csv to the archived folder
        $FilesToArchive = Get-ChildItem -Path $Path -File | Where-Object {$_.Name -notlike "*HomeBank.csv"}
        $FilesToArchive|ForEach-Object {
            $FileToArchive = $_.FullName
            Move-Item -Path $FileToArchive -Destination $PathToArchive
        }
        Write-Host "Successfully converted the CSV to a HomeBank format" -ForegroundColor Green

    }Catch{
        $e = $_.Exception
        $line = $_.InvocationInfo.ScriptLineNumber
        $msg = $e.Message

        Write-Host "caught exception: $e at $line" -ForegroundColor Red
        Write-Host "Message exception caught is $msg" -ForegroundColor Red
    }
}

Question information

Language:
English Edit question
Status:
Expired
For:
HomeBank Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.