Powershell for each line within variable
<p>I am trying to go through a variable, line by line, and apply regex to parse the string within it.</p>

<p>I am downloading the data via invoke-restmethod and am trying to do the below</p>

<pre><code>$result= invoke-restmethod -uri $uri -method get

foreach($line in $result)
if($line -match $regex)
{
   #parsing
}
</code></pre>

<p>the above doesn't work as their is only one line. But when I output result into a file and then apply the above logic it works, like so</p>

<pre><code>$result= invoke-restmethod -uri $uri -method get
$result &gt;&gt; $filelocation

$file = get-content $file
foreach($line in $file)
if($line -match $regex)
{
   #parsing
}
</code></pre>

<p>The script is time critical so I don't have the luxury to write to a file and then reopen, how could I achieve the above without using get-content?</p>