如何在 PowerShell 中生成带日期和时间的文件名
你可以像这样使用 Get-Date 生成与文件名中允许的字符兼容的日期:
date_filename.ps1
Get-Date -UFormat "%Y-%m-%d_%H-%m-%S"示例输出:
example_output.txt
2020-12-11_01-12-26为了生成完整的文件名,用 $() 包围它并在前面/后面添加你想要的文件名的其他部分:
generate_filename.ps1
mysqldump-$(Get-Date -UFormat "%Y-%m-%d_%H-%m-%S").sqlCheck out similar posts by category:
PowerShell, Windows
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow