Hello all,
Scowered many forums to get help with my issue, but no success. I have need to remove duplicates in a csv file. File is formatted like this
Server Name,DATABASE_Name,DB_Role_Type,Full_Backup,Log
Server1,E_Config,PRIMARY,12/20/2024,12/26/2024
Server1,E_SA_METADATA,PRIMARY,12/20/2024,12/26/2024
Server1,E_SA_METADATA01,PRIMARY,12/20/2024,12/26/2024
Server1,E_SA_Profile,PRIMARY,12/20/2024,12/26/2024
Server1,E_SA_Profile_Social,PRIMARY,12/20/2024,12/26/2024
Server1,E_SA_Profile_Sync,PRIMARY,12/20/2024,12/26/2024
Server1,For_AG_263,PRIMARY,12/20/2024,12/26/2024
Server2,E_SA_METADATA,SECONDARY,11/22/2024,12/11/2024
Server2,E_SA_METADATA01,SECONDARY,11/22/2024,12/11/2024
Server2,E_SA_Profile,SECONDARY,11/22/2024,12/11/2024
As can be seen there are several duplicate entries with differing backup dates. I have tried many different approaches from post I’ve read to no avail.
Most suggest the following approach, but it doesn’t seem to work for me…any guidance appreciated
# Sample of Group, Sort and Select
$CSV_Folder = "C:\Users\Downloads\"
$CSV_Name = "BackUp_report_12-26-2024.csv "
$CSV_File = $CSV_Folder+$CSV_Name
$CSV_Full = Import-Csv $CSV_File
#Group ---- Sort --- Select single newest entry
$Single_Row = $CSV_Full | Group-Object -Property DATABASE_Name | Sort-Object -Property Full_Backup -Descending | Select-Object -Property DATABASE_Name -First 1