title: HashSet in Powershell: Collection was of a fixed size
body: <p>I have a <strong>PowerShell</strong> function as follows:</p>
  
  <pre><code>Function GetAllIdentityProvidersFromDatabase {
  
      param (
          [string] $SQLConnectionSting
      )
  
      $AllIdPIdentifiers = New-Object 'System.Collections.Generic.HashSet[string]'
      $SQLConnect = new-object system.data.sqlclient.sqlconnection $SQLConnectionSting
  
      try {
          $SQLQuery = $("SELECT [IdPIdentifier] FROM [dbo].[IdPs]")
  
  
          $SQLConnect.Open()  
  
          $command = New-object system.data.sqlclient.SqlCommand   
          $command.connection = $SQLConnect  
          $command.CommandText = $SQLQuery
          $Reader = $command.ExecuteReader()
          while ($Reader.Read()) {
              $value = $Reader.GetValue($1)
              $AllIdPIdentifiers.Add($value) | Out-Null
          }
  
          $AllIdPIdentifiers
  
      } catch {
          Write-Host "SQL Select error: " $Error[0].ToString() -ForegroundColor Red
      } finally {
          $SQLConnect.Close()
      }
  }
  </code></pre>
  
  <p>Then, in another script:</p>
  
  <pre><code>$AllIdPIdentifiers = New-Object 'System.Collections.Generic.HashSet[string]'
  $AllIdPIdentifiers = GetAllIdentityProvidersFromDatabase $SQLConnectionString
  $AllIdPIdentifiers.Remove("GodspeedYou")
  Write-Host $AllIdPIdentifiers.Count
  </code></pre>
  
  <p>And by executing it, I have this error:</p>
  
  <pre><code>Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
  At C:\PowerShell\EduGain\FederationMetadataExtractor.ps1:151 char:1
  + $AllIdPIdentifiers.Remove("GodspeedYou")
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : NotSupportedException
  </code></pre>
  
  <p>Is there a way to allow the <code>Remove</code> operation?</p>