I want to create a script that will wrap logparser into Powershell and automatically analyze a set of logs. I will create a function for a lot of common analysis tasks. The issue I am having is I have a separate copy script that will go to a lot of servers, and modify the names dumping the files into one location. I append the log folder name and server name to the file. So if I have two sites on one server rather than u_ex160415.log I would have NYVPRDWEB2_W3SVC1_u_ex160415.log and NYVPRDWEB2_W3SVC2_u_ex160415.log. I end up having a folder filled with maybe 50 logs to parse through, and as you can imagine the file names vary a lot.
When I run a logparser query against the logs with a wildcard I always receive an error
logparser "SELECT * FROM C:\Logs\*.log WHERE sc-status <> 200"
The error returned is:
logparser : Error: WHERE clause: Syntax Error: unknown field 'sc-status'
From past experience I knew it was the wildcard, so instead of *.log I did
logparser "SELECT * FROM C:\Logs\NYVPRDWEB2_W3SVC1_u_ex160415.log,C:\Logs\NYVPRDWEB2_W3SVC2_u_ex160415.log WHERE sc-status <> 200"
This worked great so I figued I will just script it out to append all file names in a string that I will pass into the logparser query. I tried this:
function Get-IISErrors([Parameter(Mandatory=$true)]$LogPath,[Parameter(Mandatory=$true)]$OutputDestination,[datetime]$StartDate,[datetime]$EndDate,$DaysBack)
{
#Validate Parameters
if ($LogPath -eq '')
{
Write-Host -ForegroundColor Red "Log Path is a required parameter"
}
if ($OutputDestination -eq '')
{
Write-Host -ForegroundColor Red "Output Destination is a required parameter"
}
#Get names of Files that will be analyzed
$LogName = (Get-ChildItem $LogPath).Name
#Create String of comma separated files to be analyzed
$LogFileString = ""
foreach($x in $LogName)
{
$LogFileString = $LogFileString + "'" + $LogPath + $x + "'" + ","
}
$LastIndex = $LogFileString.Length -1
$LogFileString = $LogFileString.Substring(0,$LastIndex)
logparser "SELECT * INTO $OutputDestination FROM $LogFileString WHERE sc-status <> 200"
}
But when I run that against a large amount of files I get
'LogParser.exe' failed to run: The filename or extension is too long
I would rather figure this out using Long Parser wild cards, has anyone had luck just using *.log ? I end up using a third party tool LogLizard a lot of the time, so I am a little inexperienced when it comes to Syntax in LogParser.