Help with powershell code

Hello everyone, I have a csv file I got from exporting data from a sql database. There are 2 columns, with 1 of them being dates/times and the other a number. When i open the file in Excel the date and time is not formatted, the default formatting for the row containing the date/time shows up as Number --> Custom --> mm:ss.0. I have to select the whole column and change formatting to Date --> mm/dd/yyyy hh:mm.

Is there any way to automate the process using powershell and if so can you please provide the code? filename is test.csv and the rows do not have a header, they are row #1 and #2

thank you in advance


thank you in advance

Yes, it’s possible to manipulate csv and Excel files with PowerShell. However, for this relatively minor action it might not be worth the time to create and troubleshoot a script unless you are handling a lot of files. It might also be easier to manipulate the date/time value in PowerShell so that it is automatically recognized as a date/time by Excel, and then import the data into Excel, rather than trying to change the data format in Excel after importing.

No. This is a help & troubleshooting forum, not a “do my job for me” forum. People get paid for the kind of work you’re asking for.

A much simpler approach is to just do the sql query with Powershell so there is no need to do anything with the dates. Using the SQL module installed with SQL Management Studio is the simplest, but this list has the many ways you can interact with SQL: