Friday, September 20, 2013

Powershell Script - More Logparsing Multiple Servers

9/20/2013: I've been putting in a fair amount of time recently repetitively Logparsing the IIS logs on several regions of CAS servers

-- I'm attempting to guage MS Lync 'Exchange Web Services' load and demand on our production CAS's, ahead of new Lync capacity rollouts overseas --

So here's another quicky code chunk that I routinely grab and put to use for Logparsing multiple CAS servers of IIS logs.

It's a simple variant of my prior post "Powershell Script - Tip: Delimited String "Contants" & Multi-server Logparser scripts", only this time, rather than substitute in the entire LogPath, I'm foreach looping through the CAS server names.

Here's a specific example I just used this morning that builds a multi-server set of looped LogParser queries to pull out and group the Client 'agent' strings for all EWS traffic, and output the result into a csv file, leveraging substitution of the proper $CAS server name within the target UNC path to a log file...

Logparsing multiple servers, by foreach-ing an array variable
Here's a Gist with the code:

Static-source follows (for folks in RSS readers, or disabling scripting):
(check the linked Gist/Github links below for _current_ versions).

$CASs="US-HUBCAS1","US-HUBCAS2","US-HUBCAS3" ; 
foreach ($CAS in $CASs){
    write-host ("`n" + $CAS) ; 
    .\logparser.exe "SELECT cs(User-Agent) as Client, count(*) as Hits INTO $CAS-EWS-ALLClients.csv FROM '\\$CAS\e$\Weblogs\W3SVC1\ex130919*.log' WHERE cs-uri-stem LIKE '%/EWS/%' GROUP BY Client ORDER BY Hits DESC" -o:csv  ; 
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.