title: Cannot overwrite variable because it is readonly
body: <p>I am trying to learn Powershell. I have the following script:</p>
  
  <pre><code>$cmd = {
    param($pid)
    Write-Host $pid
  }
  
  $processes = Get-Process -Name notepad
  foreach ($process in $processes) 
  { 
      $pid = $process.ID
      Start-Job -ScriptBlock $cmd -ArgumentList $pid
  }
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <blockquote>
    <p>Cannot overwrite variable PID because it is read-only or constant. At
    line:7 char:1
    + $pid = 1
    + ~~~~~~~~
        + CategoryInfo          : WriteError: (PID:String) [], SessionStateUnauthorizedAccessException
        + FullyQualifiedErrorId : VariableNotWritable   Cannot overwrite variable PID because it is read-only or constant. At line:11 char:1
    + $pid = $process.ID
    + ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : WriteError: (PID:String) [], SessionStateUnauthorizedAccessException
        + FullyQualifiedErrorId : VariableNotWritable   Start-Job : Cannot overwrite variable pid because it is read-only or constant. At line:12
    char:5
    +     Start-Job -ScriptBlock $cmd -ArgumentList $pid</p>
  </blockquote>
  
  <p>What am I doing wrong here?</p>