Powershell Script to convert Multiple .MD files into .CSV

When I first started on my web design journey, I made a lot of bad decisions. Thankfully, the web design world is unforgiving, and taught me early. One of these bad decisions was keeping client data stored in evernote in plain text. Over the years, I migrated over to password managers, first Lastpass, then 1Password when Lastpass got hacked.

While all my current clients were successfully migrated over, my old legacy notes still lived in Evernote. They no longer posed much of a threat, as the servers that the passwords belonged to were no longer active. As a digital data hoarder, I still didn't want to lose these data points, but I didn't have a good way to migrate them over.

Evernote outputs to a proprietary file that Joplin supports thankfully, so for a while I kept them on my Joplin instance, but as someone that is trying to reduce noise, I wanted to get this out of my journal and put it someplace more secure.

Enter ChatGPT and Powershell. I had chatgpt create a powershell script for me that took all the Markdown Files and converted them over to CSV file that I can then import into 1Password. I first created an Archive Vault for these so I also don't see them on the day to day, but can search against them if I need to.

See below:

# Initialize an empty array to hold the data
$csvData = @()

# Debug: Print the directory being scanned
Write-Host "Scanning directory: C:\Users\USER\OneDrive\Desktop\Old Business Notes"

# Loop through each .md file in the folder
Get-ChildItem -Path 'C:\Users\USER\OneDrive\Desktop\Old Business Notes' -Filter *.md | ForEach-Object {
    # Debug: Print the name of the file being processed
    Write-Host "Processing file: $($_.Name)"

    # Read the file content
    $fileContent = Get-Content $_.FullName -Raw
    
    # Debug: Print the file content
    Write-Host "File Content: $fileContent"

    # Separate the title and content
    $lines = $fileContent -split "\r?\n"
    $title = $_.BaseName  # Using the filename without extension as the title
    $content = $lines -join "`r`n"
    
    # Create an object for this file
    $obj = [PSCustomObject]@{
        "Title" = $title
        "Content" = $content
    }
    
    # Add the object to the array
    $csvData += $obj
}

# Debug: Print the CSV data to the console
Write-Host "CSV Data: $csvData"

# Export the array to CSV
$csvData | Export-Csv -Path 'C:\Users\USER\OneDrive\Desktop\Old Business Notes\output.csv' -NoTypeInformation

# Debug: Check if the file has been created
if (Test-Path 'C:\Users\USER\OneDrive\Desktop\Old Business Notes\output.csv') {
    Write-Host "CSV file created successfully."
} else {
    Write-Host "CSV file NOT created."
}
Back to Articles Subscribe by Email