title: Cannot overwrite variable false because it is read-only or constant
body: <p>Here is my code where I have included relevant parts:</p>
  
  <pre><code>Get-ChildItem -LiteralPath $somepath -Directory | ForEach-Object {
      Step $_.FullName
  }
  
  function Step {
      Param([string]$subfolder)
  
      $folders = Get-ChildItem -LiteralPath $subfolder -Directory -ErrorVariable $HasError -ErrorAction SilentlyContinue
  
      if ($HasError) {
          Write-Host $_.FullName "|" $HasError.Message
          return
      } else {
          $hasError, $inactive = FolderInactive $_.FullName
          if ($hasError) {
              #do nothing
          } else {
              if ($inactive) {
                  SetFolderItemsReadOnly $_.FullName
              }
          }
      }
  
      if ($folders) {
          $folders | ForEach-Object {
              Step $_.FullName
          }
      }
  }
  
  function SetFolderItemsReadOnly {
      Param([string]$Path)
  
      $files = Get-ChildItem -LiteralPath $Path -File -ErrorAction Stop
  
      foreach ($file in $files) {
          try {
              Set-ItemProperty -LiteralPath $file.FullName -Name IsReadOnly -Value $true
          } catch {
              Write-Host $file.FullName " | " $_.Exception.Message
          }       
      }
  }
  </code></pre>
  
  <p>I get some errors with <code>Set-ItemProperty</code> in the <code>SetFolderItemsReadOnly</code> function, that is</p>
  
  <blockquote>
    <p>Exception setting "IsReadOnly": "Access to the path is denied."</p>
  </blockquote>
  
  <p>which is due to some security permissions. However after printing this error in the terminal I also get a huge red error like so:</p>
  
  <pre>Cannot overwrite variable false because it is read-only or constant.
  At pathtoscript:55 char:5
  +     $folders = Get-ChildItem -LiteralPath $subfolder  -Directory -ErrorVariable  ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (false:String) [], SessionStateUnauthorizedAccessException
      + FullyQualifiedErrorId : VariableNotWritable</pre>
  
  <p>Why does this error occur?</p>