Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem: Could not assign result, returned from foreach, to a variable

20 views
Skip to first unread message

kostya....@googlemail.com

unread,
Feb 12, 2013, 4:50:11 AM2/12/13
to
Hi experts,

I have a following head-breaking problem. When I'm trying to execute script below, I get an error:

Error "=" operator: System error. (Fehler beim "="-Operator: Systemfehler.)
+ $data = <<<< Get-Content $log | % {

Here is this script:

$log = "C:\log file.txt"
$linePrefix = "PROCESS THIS LINE"
$trimStart = 25 #chars to ignore in the beginning
$started = 0

$data = Get-Content $log | % { if ($_.length -ge $trimstart) { $linedata = $_.substring($trimstart); $timesline = $linedata.startswith($lineprefix); if ($started -eq 0 -and $timesline) { $started = 1; }; if ($started) { if ($timesline) { $line = $linedata.substring($lineprefix.length).trimstart(); if ($line.contains(": ")) { write-output $line } } else { break; } } } }

However, if I execute it without "$data = " assignment, it works perfectly and returns me expected values. I've also tried following statement

$data = (...)

but with no success.

Could you please give me a hint why it does happen?

kostya....@googlemail.com

unread,
Feb 12, 2013, 4:55:23 AM2/12/13
to
Oh yeah, I work on 32bit Windows 2003 and Powershell 1.0

kostya....@googlemail.com

unread,
Feb 13, 2013, 5:51:43 AM2/13/13
to
0 new messages