title: How to solve error: Exception setting "Value": "Value does not fall within the expected range." in powershell script
body: <p>I am passing in a hash table of parameters for Oracle insertion. The contents of the hash table Value is an array. I keep getting this error:</p>
  
  <pre><code>Exception setting "Value": "Value does not fall within the expected range."
  </code></pre>
  
  <p>When I try and add the value using array binding. I have a valid command object and I set the ArrayBindCount to the correct value. Here the code I am using and the output. This should work! Note that the $parameterValues variable contains my hash table that I am passing in:</p>
  
  <pre><code>$cmdObject = New-Object Oracle.DataAccess.Client.OracleCommand($sqlStatement,$connectionObject)
   $cmdObject.BindByName = $true
  
  if($parameterValues)
   {
    ForEach($p in $parameterValues.GetEnumerator())
    {
     $cmdObject.ArrayBindCount = $p.Value.Count
     Write-Host ("ParameterName = ""{0}"" type = {1} Parameter Value Type = {2} Count = {3}" -f $p.Key, $p.Key.GetType().FullName, $p.Value.GetType().FullName, $p.Value.Count)
     $oraParam = New-Object Oracle.DataAccess.Client.OracleParameter
     $oraParam.ParameterName = $p.Key
     $oraParam.Value = $p.Value
     $cmdObject.Parameters.Add($oraParam) | Out-Null
    }
  
    Write-Host("Number of parameters in `$cmdObject.Parameters = {0}" -f $cmdObject.Parameters.Count)
  
  Write-Host ("Value of `$cmdObject.ArrayBindCount = {0}" -f $cmdObject.ArrayBindCount)
  </code></pre>
  
  <p>Here is the output and error I am getting:</p>
  
  <pre><code>    Value of $cmdObject.CommandText =  insert into regions (region_id, region_name) values (:REGION_ID, :REGION_NAME)
  ParameterName = "REGION_NAME" type = System.String Parameter Value Type = System.String[] Count = 4
      Exception setting "Value": "Value does not fall within the expected range."
      At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
      +    $oraParam.Value = $p.Value
      +    ~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
          + FullyQualifiedErrorId : ExceptionWhenSetting
  
      ParameterName = "REGION_ID" type = System.String Parameter Value Type = System.Int32[] Count = 4
      Exception setting "Value": "Value does not fall within the expected range."
      At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
      +    $oraParam.Value = $p.Value
      +    ~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
          + FullyQualifiedErrorId : ExceptionWhenSetting
  
      Number of parameters in $cmdObject.Parameters = 2
      Value of $cmdObject.ArrayBindCount = 4
  </code></pre>
  
  <p>I just cannot get this to work! Please help!</p>