How to generate filename with date and time in PowerShell
You can use Get-Date like this to generate a date that is compatible with characters allowed in filenames:
date_filename.ps1
Get-Date -UFormat "%Y-%m-%d_%H-%m-%S"Example output:
example_output.txt
2020-12-11_01-12-26In order to generate a complete filename, surround that with $() and prepend/append other parts of your desired filename:
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