Cool!

I've never used StartsWith() before. Thanks for pointing it out.

I think that's a pretty PowerShell'ed routine now.

Regards,

Michael B. Smith
MCSE/Exchange MVP
http://TheEssentialExchange.com


-----Original Message-----
From: Campbell, Rob [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 18, 2008 8:56 AM
To: MS-Exchange Admin Issues
Subject: RE: Mailbox Count

Pretty close.  I had to make a couple of adjustments, and ended up with:

gci MSGTRK*.log -name |% {
        $src_evt_ht = @{}
        
        write-host
        $_
        gc $_ | 
        foreach {
                if ($_.startswith("2")){
                        $rec = $_ -split ","

                        $src_evt_ht[($rec[7] + "." + $rec[8])] += 1
                }
        }

        write-host
        $src_evt_ht
}



The "if ($_[0] -neq "#")" was only going to work if each line returned
by gc got converted to a char array first.  That seemed a little heavy
handed processor wise for what I needed it to do.  

I did a get-member on a test string, and notice that startswith() method
which looked promising.  I originally tried:

if (!($rec.startswith("#"))){

That worked but looked awful.  

 If ($rec.startswith("2")) looked cleaner, and should work for the next
992 years.

-----Original Message-----
From: Michael B. Smith [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 17, 2008 4:38 PM
To: MS-Exchange Admin Issues
Subject: RE: Mailbox Count

Slightly denser (untested but seems right):

gci MSGTRK*.log -name |% {
        $src_evt_ht = @{}

        $_.Name
        gc $_ | 
        foreach {
                if ($_[0] -neq "#"){
                        $rec = $_ -split ","

                        $src_evt_ht.[($rec[7] + "." + $rec[8])] += 1
                }
        }

        write-host
        $src_evt_ht
}

Regards,

Michael B. Smith
MCSE/Exchange MVP
http://TheEssentialExchange.com


-----Original Message-----
From: Campbell, Rob [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 17, 2008 3:54 PM
To: MS-Exchange Admin Issues
Subject: RE: Mailbox Count



Thanks!  That makes it much easier!

$logfiles = gci MSGTRK*.log
foreach ($logfile in $logfiles){

$src_evt_ht = @{}

gc $logfile |% {

if ($_ -notmatch "^\#.+$"){
$rec = $_ -split ","

$source = $rec[7]
$event_id = $rec[8]


$src_evt = $source + "." + $event_id

$src_evt_ht.$src_evt += 1

}
}

$logfile.name
write-host "`n"
$src_evt_ht


}




-----Original Message-----
From: Michael B. Smith [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 17, 2008 2:08 PM
To: MS-Exchange Admin Issues
Subject: RE: Mailbox Count

Associative arrays (hash tables) support "Lazy Add". So this

if ($src_evt_ht.$src_evt){$src_evt_ht.$src_evt =
[int]$src_evt_ht.$src_evt + 1}
else {$src_evt_ht.add("$src_evt","1")}

just needs to be

$src_evt_ht[$src_evt] += 1

Regards,

Michael B. Smith
MCSE/Exchange MVP
http://TheEssentialExchange.com


-----Original Message-----
From: Campbell, Rob [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 17, 2008 1:23 PM
To: MS-Exchange Admin Issues
Subject: RE: Mailbox Count

Something I was messing with last night:

$logfiles = gci MSGTRK*.log
foreach ($logfile in $logfiles){

$src_evt_ht = @{}

gc $logfile |% {

if ($_ -notmatch "^\#.+$"){
$rec = $_ -split ","

$source = $rec[7]
$event_id = $rec[8]


$src_evt = $source + "." + $event_id
if ($src_evt_ht.$src_evt){$src_evt_ht.$src_evt =
[int]$src_evt_ht.$src_evt + 1}
else {$src_evt_ht.add("$src_evt","1")}
}
}

$logfile.name
write-host "`n"
$src_evt_ht


}


************************************************************************
****
********************** 
Note: 
The information contained in this message may be privileged and
confidential
and 
protected from disclosure.  If the reader of this message is not the
intended  
recipient, or an employee or agent responsible for delivering this
message
to  
the intended recipient, you are hereby notified that any dissemination,

distribution or copying of this communication is strictly prohibited. If
you

have received this communication in error, please notify us immediately
by  
replying to the message and deleting it from your computer. 
************************************************************************
****
**********************

~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~


~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~

****************************************************************************
********************** 
Note: 
The information contained in this message may be privileged and confidential
and 
protected from disclosure.  If the reader of this message is not the
intended  
recipient, or an employee or agent responsible for delivering this message
to  
the intended recipient, you are hereby notified that any dissemination,   
distribution or copying of this communication is strictly prohibited. If you

have received this communication in error, please notify us immediately by  
replying to the message and deleting it from your computer. 
****************************************************************************
**********************

~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~


~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~

Reply via email to