Log Parser for filenames with dates (PowerShell) Template

Version 2

    Our company has a bunch of custom server applications that all write logs that include the date in the filename. For example, the filename for the 7th might be ServerApp1_07.txt. The out-of-the-box Log Parser template can only handle static filenames.

     

    I am sure there are other products that create dated log files so I added a couple lines to the Log Parser scripts that allow it to build a file path based on the current date and a format provided as an argument.

     

    The new format for arguments is:

     

    Base file path,date format, file extension, regex

     

    For example:

    D:\powertest_,dd,txt,string

    will search for "string" in the file D:\powertest_01.txt on the 1st of the month, D:\powertest_02.txt on the 2nd, etc.

     

    NOTE: The scripts do not validate the date format argument. Make sure that yours is correct. See the following MSDN article for more information: https://msdn.microsoft.com/library/system.globalization.datetimeformatinfo.aspx#properties

     

    The changes were that this:

    # Arguments example: d:\powertest.txt,string
    $logfile_path = $args.get(0);
    $regex = $args.get(1);
    $Error.Clear();

     

    became:

    # Arguments example: d:\powertest_,dd,txt,string
    $logfile_base = $args.get(0);
    $date_format = $args.get(1);
    $file_extension = $args.get(2);
    $regex = $args.get(3);
    $date_to_append = Get-Date -format $date_format;
    $logfile_path = $logfile_base + $date_to_append + "." + $file_extension
    $Error.Clear();

     

    in the Total number of strings found and Number of newly found strings monitors. The Found string in # position script has an additional argument for the position which remains the last argument. Otherwise the changes were the same.