Import csv file and resort last column than export to different filename.csv

Here is what I tried but it didn’t work.

Import-csv C:\astig\cbi\agents15975.csv | sort last_modified -Descending | Export-csv -Path C:\astig\cbi\agents.csv -NoTypeInformation

Welcome to the forum. :wave:t4:

What exactly do you mean with …


Regardless of that - when you post code please format it as code using the preformatted text button ( </> ). Simply place the cursor on an empty line, click the button and paste your code.

Thanks in advance.

please try this.

Import-csv C:\astig\cbi\agents15975.csv | sort-object -property last_modified -Descending | Export-csv -Path C:\astig\cbi\agents.csv -NoTypeInformation

Where is the difference to the original code? :thinking:

And regardless of that - how about indenting the code for better readability? :wink:

1 Like

[Chen.Chen] Thanks for the addition of the code “sort-object” to my code. It worked great. Thanks

Yes, we should make the code readable. but sometimes if the alias doesn’t wrok, should we try to use the completed code to test?
I have met this problem. sort XXX not wroked. and I try to use the completed code. then It worked.
and I have no idea what happened. maybe I have some mistake in the postition of parameters or other property or something. But use completed code can fix it.


Thank you for your help and the code to try. After a slight modification on the object field, it worked perfectly,

I have no idea who “OLAF" is but those comments didn’t help[p at all.

Darrell Orcutt


@tigsystems “OLAF” is another guru who is very helpful in getting NOOBs (and dunces) up to speed, so to speak, to affect positive results in their pleas for help. CLOSE ATTENTION should be paid to whatever comment (albeit cryptic and even seemingly off-point) them may appear.

You come seeking a quick and explicit solution. “OLAF” is a genius in pointing the way to what your ultimate desire is (even it requires your threading through a bramble-bush).

FWIW: be grateful that “OLAF” bothered to comment to your foooolish request. jus’ sayin’