![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||