Fred_Elmendorf
Mar 10, 2023Brass Contributor
Dynamically created file name using present system time.
Each time I run my script I need to create a new file name that includes the system date and time to reflect the script run time. The desired output file name would look something like this:
My Output File yyyyddmm.hhmmss.csv
Any assistance greatly appreciated!
Thanks,
Fred
Having put a fuller example in your other post, I'll simply say that to change the $LogFile name to include a timestamp would simply involve changing Line 1 from that example to something like the following:
$LogFile = ".\SomeLogFile-$([datetime]::Now.ToString("yyyyMMdd HHmmss")).log";
From that small change, I get the CSV output log filename of:
SomeLogFile-20230316 175653.log
Cheers,
Lain