I have the following code:
$script:DatabaseFile = "C:\NewFolder\test.csv"
[string[]]$database = Get-Content -Path $script:DatabaseFile
[Collections.Generic.List[String]]$script:Database = $database
$script:Database | Out-File $script:DatabaseFile -Encoding ascii
$databaseAsCsvObject = Import-Csv $script:DatabaseFile
$databaseAsCsvObject | sort "Release Group","Email Address" | Export-Csv $script:DatabaseFile
$script:DatabaseFile contains the following:
Release Group,Email Address,Template ID,Time
CDP.HLO.1,[email protected],Template1,02:00
EDP.HLO.1,[email protected],Template2,03:00
This successfully sorts the csv file based on the first two columns.
How can I write the equivalent code without having to save the file, then import it as csv?
Can I just get $script:Database as a "CSV" object, and then sort it, and then write it to file only once?