Author Posts

January 1, 2012 at 12:00 am

by Dwayne Dibbley at 2012-12-23 11:38:13

my receive-job output looks like this:

Updating group freddy
Processing freddy
Group freddy has 1,008 new parts.
First: 353105746 Last: 1199398789 Local last: 1199397781
Getting 1,008 parts (1199397782 to 1199398789) - 0 in queue
Received 1007 articles of 1008 requested, 0 blacklisted, 0 not binaries
Server did not return 1 article(s).
7 new, 77 updated, 1,007 parts. 0.45 headers, 1.38 update, 1.82 range.
Group processed in 2.12 seconds

currently i use this to pull back the number of new parts:

(receive-job freddy | Where-Object {$_ -match "new parts."}).trim().split(" ")[3] + " new parts."

my question is can i also pull back the Group processed in time in the same where-object? or would i need to run the receive-job twice?

Thanks

by nohandle at 2012-12-24 03:49:53

Try this, and let us know if there is anything unclear in the script. 🙂
#prepare data as array of lines to mimick your situation
$output = @'
Updating group freddy
Processing freddy
Group freddy has 1,008 new parts.
First: 353105746 Last: 1199398789 Local last: 1199397781
Getting 1,008 parts (1199397782 to 1199398789) - 0 in queue
Received 1007 articles of 1008 requested, 0 blacklisted, 0 not binaries
Server did not return 1 article(s).
7 new, 77 updated, 1,007 parts. 0.45 headers, 1.38 update, 1.82 range.
Group processed in 2.12 Seconds
'@ -split "`n"

#process the data
$output |
#if you need to process more reports than one add another layer of foreach
ForEach-Object -Begin {
$object = New-Object psObject
} -process {
#use named submatches. *? to be ungreedy
if ($_ -match 'Group (?.*?) has (?.*?) new')
{
#add object properties
Add-Member -InputObject $object -MemberType NoteProperty -Name NewParts -Value $matches.NewParts
Add-Member -InputObject $object -MemberType NoteProperty -Name GroupName -Value $matches.GroupName
}
if ($_ -match 'Group processed in (?

} -End {
#output the whole object
$object
}

NewParts GroupName Time
-------- --------- ----
1,008 freddy 00:00:02