Import-Csv and sort by end of column cell value


I’m not sure if it’s possible but it usually is with PowerShell :wink:

Anyway. I’m importing a csv file using the below:

[array]$AllClientsBody = @()
Foreach ($Path in $TargetPaths) { #}
# Extract the client name from path
$Client = ($Path -split ‘\’)[6]
# Import CSV file, create custom headers, skip the csv headers row, get the last row data only & convert to HTML formatting
$csvHTML = Import-Csv -Path “$Path\TotalMonthlyTransactions.csv” -Header “Month”,“Transactions” | Select-Object -Skip 1 | Select-Object -Last 1 | ConvertTo-Html -Fragment
# Construct the email body and populate with imported information
$MailBody = “Total Monthly Transactions for $Client</br>$csvHTML</br>”
# Add the client email body to the array so it can be sent in one email
$AllClientsBody += $MailBody

The problem is that the ordering in the first column is like this:

January 2017
January 2018
January 2019
January 2020
February 2017
February 2018

Is some jiggery pokery that allows me to sort this on the latter part of the value and then the first?