Forum Discussion

Fred_Elmendorf's avatar
Fred_Elmendorf
Copper Contributor
Mar 10, 2023
Solved

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 O...
  • LainRobertson's avatar
    LainRobertson
    Mar 16, 2023

    Fred_Elmendorf 

     

    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

Resources