简体   繁体   中英

Export as CSV on Powershell with output file name as timestamp

I need to export a script as a timestamped csv and this isn't an existing csv. I'm running a command to get data and I need the output to be exported as a timestamp (month, day, year, hour, minute). I tried from others but it seems they're doing it from an already existing csv and changing the name to timestamp. Here's that part of my script:

Export-Csv -Path "C:\Parts\PartOne\Automation\$(Get-Date -UFormat '%Y%m%d_%H%M%S').csv" -NoTypeInformation

I need it to grab the current date of when the command was run and output.

You could try setting the content to be exported and then export to CSV?

Ex.

$content = Get-Content -Path "C:\PathToYourFile"

$content | Export-Csv -Path "C:\Parts\PartOne\Automation\$(Get-Date -UFormat `'%Y%m%d_%H%M%S').csv" -NoTypeInformation`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM