I’m completely new to powershell and don’t have much experience working on Windows servers so please forgive me if this is a simple problem. The server has the AWS CLI installed and I need to sort the ls command by date and get the most recent file in the bucket. The command aws s3 ls s3://mybucket/myfolder/ outputs a listing like so with no headers:
I’ve tried piping the output to Sort Date -Descending but that has no affect on the output. I’ve managed to successfully isolate the datetime part with a regex and “select-string” but I still don’t seem to be able to sort it properly.
All that said, I was hoping somebody could help me find the best way to get the most recent file from a listing like that.
This gets the contents of the bucket, sorts by the ‘lastmodified’ date, and selects the last entry. For demonstration I then display it as a table.
If you cannot load the AWS module, then maybe have the AWS CLI save as JSON and import the JSON in PowerShell. Otherwise you are stuck with having to manipulate the AWS output as text in PowerShell, which just makes everything harder.
Viewing 1 reply thread
The topic ‘Get most recent file from AWS s3 ls command’ is closed to new replies.