[System.Object[]] doesn't contain a methodnamed 'replace'
<p>The following is part of the file edit07.html:<br>
From <code>$array</code> I'm able to access the <code>$empid = $user.employeeid</code> and 
<code>$seat = $user.Position</code>. The part where is code breaks is</p>

<pre><code>$filecontent = $filecontent.replace($pattern01,$new01)
</code></pre>

<p>This works on PowerShell version 3, but I get</p>

<blockquote>
  <p>[System.Object[]] doesn't contain a methodnamed 'replace'</p>
</blockquote>

<p>when I run it with PowerShell version 2.</p>

<p><code>edit07.html</code>:</p>

<pre class="lang-html prettyprint-override"><code>&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=1&gt;&lt;/td&gt;
&lt;td colspan=5&gt;&lt;/td&gt;
&lt;td colspan=3 rowspan=4 align=left valign=top&gt;&lt;a
href="https://athena/empstatus/getcontact.asp?empid=238735#23-006&amp;#13;"&gt;

&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td colspan=2&gt;&lt;/td&gt;
&lt;td colspan=3 rowspan=4 align=left valign=top&gt;&lt;a
href="https://athena/empstatus/getcontact.asp?empid=126086#23-017&amp;#13;"&gt;

&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td colspan=3 rowspan=4 align=left valign=top&gt;&lt;a
href="https://athena/empstatus/getcontact.asp?empid=39#23-028&amp;#13;"&gt;
</code></pre>

<p>The line:</p>

<pre class="lang-html prettyprint-override"><code>href="https://athena/empstatus/getcontact.asp?empid=39#23-028&amp;#13;"&gt;
</code></pre>

<p>needs to be replaced with:</p>

<pre class="lang-html prettyprint-override"><code>"href=""#"" data`enter code here`toggle=""tooltip""title=""$tooltip""onClick=""window.open('
https://athena/empsta   tus/getcontact.asp?empid=" + $empid + "','mywindow','width=282,height=325,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no,style=text-`decoration:none')")
</code></pre>

<p>The <code>$array</code> looks like the following</p>

<pre>Position     : 28-015
FirstName    : Marry
LastName     : Hay
PhoneNumber  : 448
Department   : IT
ComputerName : KURO-36
employeeid   : 245423
mail         : 

Position     : 28-016
FirstName    : Jimmy
LastName     : Jay
PhoneNumber  : 346
Department   : Researchers
ComputerName : SOBU-04
employeeid   : 231690
mail         : 

Position     : 28-018
FirstName    : Jack
LastName     : Johnson
PhoneNumber  : 454
Department   : Operations
ComputerName : SOBU-06
employeeid   : 384737
mail         : 

Position     : 28-022
FirstName    : Joe
LastName     : Blow
PhoneNumber  : 319
Department   : Operations
ComputerName : MITA-54
employeeid   : 100083
mail         : </pre>

<pre><code>$fileContent = Get-Content 'c:\temp\edit07.html'

foreach ($user in $array) {
  $empid = $user.employeeid

  $fname = $user.FirstName
  $lname = $user.LastName
  $phone = $user.PhoneNumber
  $pc = $user.ComputerName
  $seat = $user.Position

  $tooltip = @"
$fname
$lname
$phone
$pc
$seat
"@

  $find01    = 'href="https://athena/empstatus/getcontact.asp?empid=' + $empid + '#' + $seat + '&amp;#13;"&gt;'

  $replace01 = "href=""#"" data-toggle=""tooltip""title=""$tooltip""onClick=""window.open('https://athena/empstatus/getcontact.asp?empid=" + $empid +       "','mywindow','width=282,height=325,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no,style=text-        decoration:none')"

  $empid
  $pattern01 = $find01
  $new01 = $replace01
  $strreplace01 = [regex]::replace($empid, $pattern01, $new01) 

  $filecontent = $filecontent.replace($pattern01,$new01)
  #$filecontent  -replace $pattern01,$new01
}

$fileContent | Set-Content 'c:\temp\edit08.html'
</code></pre>

<p>when I use PowerShell version 2 I get this error message:</p>

<pre>Method invocation failed because [System.Object[]] doesn't contain a method
named 'replace'.
At line:38 char:40
+     $filecontent = $filecontent.replace &lt;&lt;&lt;&lt; ($pattern01,$new01)
    + CategoryInfo          : InvalidOperation: (replace:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound</pre>

<p>I also tried:</p>

<pre><code>$filecontent = [System.IO.File]::ReadAllText($filecontent).replace($pattern01,$new01)
</code></pre>

<p>and</p>

<pre><code>$filecontent -replace $pattern01,$new01
</code></pre>