Scripting Question

AW stats Output log files

11/14/2016 937 views
Hello all, 

I have been writing a powershell script that reads monthly IIS logs from a folder and generates AWstats output files. The IIS log files are named in chronological order ( by date) 

 This is my bit of code so far

$Dir = "F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept"

$Files = get-childitem $Dir\*.* -include *.txt
$List = $Files | where {$_.extension -eq ".txt"}
foreach ($File in $Files)
perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File}

This currently writes to host but I would like to Output each file in the monthly folder to an output file , the output folder using name convention "*Month* run *day*.txt" For example , for September 1st.. "Septrun1"  , September 2nd "Septrun2" 

The month can be a variable from the Input folder (F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept)

Any advice on how I can best achieve this?

0 Comments   [ + ] Show comments


  • This content is currently hidden from public view.
    Reason: Removed by member request For more information, visit our FAQ's.

Community Chosen Answer

Need more information about the folder structure, as we need that to create the output file, but you could do something like this.

Comment out the bits to test one or the other. I think the below will not output to console as its being piped. If you need to show on screen and output you could run the command twice. Ie Once to show on screen, then second to bash to file.

Not sure what your doing with $List, assume your doing something else later in the script with it.

The output file name could be better, but without knowing your file structure, its hard to create this file mask.

$Dir = "F:\AWStats_App\Input_SourceLogFiles_Temp\App1\Sept"

$Files = get-childitem $Dir\*.* -include *.txt
$List = $Files | where {$_.extension -eq ".txt"}

Foreach ($File in $Files)
    {#Prep output filename 
      $OutputFileName = $File.BaseName + '_ProcessedLog.log'
     #Try this first, not sure if it will show on screen while it pipes.
     & perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File | Out-File "$Dir\$OutputFileName"

     #Try this second
     $ProcessedLog = & perl.exe F:\Tomcat8\webapps\awstats-7.5\wwwroot\cgi-bin\awstats.pl config=app logfile=$File
     $ProcessedLog | Out-File "$Dir\$OutputFileName"}
Answered 11/14/2016 by: rileyz
Red Belt

All Answers

Thanks Riley!! the output folder is F:\AWStats_App1\Output_RunLogs\App1\Sept

As for the $list actually I was meant to comment that out as not required any more.
Answered 11/14/2016 by: TonyFishers
Yellow Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ