Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Working with Piped output

Reply
 
Old 08-28-2008   #1 (permalink)
NPopovich


 
 

Working with Piped output

I have a PS script that queries an event log and pipes the output of the log
to text file. then i need to get-content and get a guid from the textfile
using a regex. but the piped output is read as seperate strings and is
screwing up. Everything works fine when the output is a contigious string
(for testing). help me out, please. i've tried out-string.

the regex works, but the output of the get-eventlog cmdlet seperates
everything into dif strings so that the GUID never appears like this ( GUID )
but rather this: ( GU

ID)


SCRIPT STARTS HERE:


$a = get-date
$LogTime = $a.toshortdatestring()

get-eventlog -newest 10 -logname "Operations Manager" | where {$_.EventID
-eq 33333 -and $_.message -like "*777980008*" -and $_.TimeWritten -like
"$LogTime*"} | format-list * | out-file "C:\AlertBody.txt"

$ProxyAlert= gc "C:\AlertBody.txt"

$AgentGuid=if($ProxyAlert -match '\( ([-a-z0-9]+) \) '){$matches[1]}

SCRIPT STOPS HERE

For formatting reasons i can send anyone the textfile outputs that work (i
manually cut and paste), and the output that doesn't work (from the cmdlet
pipe)

Thanks!





My System SpecsSystem Spec
Old 08-28-2008   #2 (permalink)
NPopovich


 
 

RE: Working with Piped output

And the regex doesn't work... because i'm lame.

"NPopovich" wrote:
Quote:

> I have a PS script that queries an event log and pipes the output of the log
> to text file. then i need to get-content and get a guid from the textfile
> using a regex. but the piped output is read as seperate strings and is
> screwing up. Everything works fine when the output is a contigious string
> (for testing). help me out, please. i've tried out-string.
>
> the regex works, but the output of the get-eventlog cmdlet seperates
> everything into dif strings so that the GUID never appears like this ( GUID )
> but rather this: ( GU
>
> ID)
>
>
> SCRIPT STARTS HERE:
>
>
> $a = get-date
> $LogTime = $a.toshortdatestring()
>
> get-eventlog -newest 10 -logname "Operations Manager" | where {$_.EventID
> -eq 33333 -and $_.message -like "*777980008*" -and $_.TimeWritten -like
> "$LogTime*"} | format-list * | out-file "C:\AlertBody.txt"
>
> $ProxyAlert= gc "C:\AlertBody.txt"
>
> $AgentGuid=if($ProxyAlert -match '\( ([-a-z0-9]+) \) '){$matches[1]}
>
> SCRIPT STOPS HERE
>
> For formatting reasons i can send anyone the textfile outputs that work (i
> manually cut and paste), and the output that doesn't work (from the cmdlet
> pipe)
>
> Thanks!
>
>
>
>
My System SpecsSystem Spec
Old 08-28-2008   #3 (permalink)
NPopovich


 
 

RE: Working with Piped output

ok, got the regex

($proxyalert -match '\( ([-a-z0-9]+) \) ')

$AgentGUID=$matches[1]


"NPopovich" wrote:
Quote:

> And the regex doesn't work... because i'm lame.
>
> "NPopovich" wrote:
>
Quote:

> > I have a PS script that queries an event log and pipes the output of the log
> > to text file. then i need to get-content and get a guid from the textfile
> > using a regex. but the piped output is read as seperate strings and is
> > screwing up. Everything works fine when the output is a contigious string
> > (for testing). help me out, please. i've tried out-string.
> >
> > the regex works, but the output of the get-eventlog cmdlet seperates
> > everything into dif strings so that the GUID never appears like this ( GUID )
> > but rather this: ( GU
> >
> > ID)
> >
> >
> > SCRIPT STARTS HERE:
> >
> >
> > $a = get-date
> > $LogTime = $a.toshortdatestring()
> >
> > get-eventlog -newest 10 -logname "Operations Manager" | where {$_.EventID
> > -eq 33333 -and $_.message -like "*777980008*" -and $_.TimeWritten -like
> > "$LogTime*"} | format-list * | out-file "C:\AlertBody.txt"
> >
> > $ProxyAlert= gc "C:\AlertBody.txt"
> >
> > $AgentGuid=if($ProxyAlert -match '\( ([-a-z0-9]+) \) '){$matches[1]}
> >
> > SCRIPT STOPS HERE
> >
> > For formatting reasons i can send anyone the textfile outputs that work (i
> > manually cut and paste), and the output that doesn't work (from the cmdlet
> > pipe)
> >
> > Thanks!
> >
> >
> >
> >
My System SpecsSystem Spec
Old 08-28-2008   #4 (permalink)
NPopovich


 
 

RE: Working with Piped output

ok, i figured it out:

select-object -expand was the key for me. My finished piece:

$proxyalert=get-eventlog -newest 20000 -logname "Operations Manager" | where
{$_.EventID -eq 33333 -and $_.message -like "*777980008*" -and $_.TimeWritten
-like "$
LogTime*"} | select-object -expand ReplacementStrings

AgentGuid=$matches[1]

"NPopovich" wrote:
Quote:

> ok, got the regex
>
> ($proxyalert -match '\( ([-a-z0-9]+) \) ')
>
> $AgentGUID=$matches[1]
>
>
> "NPopovich" wrote:
>
Quote:

> > And the regex doesn't work... because i'm lame.
> >
> > "NPopovich" wrote:
> >
Quote:

> > > I have a PS script that queries an event log and pipes the output of the log
> > > to text file. then i need to get-content and get a guid from the textfile
> > > using a regex. but the piped output is read as seperate strings and is
> > > screwing up. Everything works fine when the output is a contigious string
> > > (for testing). help me out, please. i've tried out-string.
> > >
> > > the regex works, but the output of the get-eventlog cmdlet seperates
> > > everything into dif strings so that the GUID never appears like this ( GUID )
> > > but rather this: ( GU
> > >
> > > ID)
> > >
> > >
> > > SCRIPT STARTS HERE:
> > >
> > >
> > > $a = get-date
> > > $LogTime = $a.toshortdatestring()
> > >
> > > get-eventlog -newest 10 -logname "Operations Manager" | where {$_.EventID
> > > -eq 33333 -and $_.message -like "*777980008*" -and $_.TimeWritten -like
> > > "$LogTime*"} | format-list * | out-file "C:\AlertBody.txt"
> > >
> > > $ProxyAlert= gc "C:\AlertBody.txt"
> > >
> > > $AgentGuid=if($ProxyAlert -match '\( ([-a-z0-9]+) \) '){$matches[1]}
> > >
> > > SCRIPT STOPS HERE
> > >
> > > For formatting reasons i can send anyone the textfile outputs that work (i
> > > manually cut and paste), and the output that doesn't work (from the cmdlet
> > > pipe)
> > >
> > > Thanks!
> > >
> > >
> > >
> > >
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Return from a piped foreach in function PowerShell
String formatting of piped dates PowerShell
Import-CSV piped hashtable access PowerShell
S-video output not working Vista music pictures video
Component output not working? Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46