简体   繁体   English

在 Powershell 上导出为 CSV 并使用 output 文件名作为时间戳

[英]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.我需要将脚本导出为带时间戳的 csv,这不是现有的 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).我正在运行一个命令来获取数据,我需要将 output 导出为时间戳(月、日、年、小时、分钟)。 I tried from others but it seems they're doing it from an already existing csv and changing the name to timestamp.我尝试过其他人,但似乎他们是从已经存在的 csv 中进行的,并将名称更改为时间戳。 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.我需要它来获取命令运行的当前日期和 output。

You could try setting the content to be exported and then export to CSV?您可以尝试设置要导出的内容,然后导出到 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`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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