title: Out-Gridview not passing selection to variable
body: <p>I have created the below script which takes values assigned to an array $PerfList and displays them using Out-Gridview. Once the selection is made it should pass the selection to $Server, but doesn't. I get the following error:</p>
  
  <blockquote>
    <p>Index operation failed; the array index evaluated to null. At
    C:\CreateStart.ps1:7 char:21
    +           foreach { $PerfList[$_.IDX] })
    +                     ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : NullArrayIndex</p>
  </blockquote>
  
  <p>My code is as follows:</p>
  
  <pre><code>$PerfList = @("Primary", "SQL", "APE", "Netflow", "AWE")
  $IDX = 0
  $Server = ($(foreach ($item in $PerfList){
            $item | select @{l='#';e={$IDX}},@{l='Name';e={$PerfList[$IDX]}}
            $IDX++}) | 
            Out-Gridview -Title 'What server is this?' -OutputMode Single |
            foreach { $PerfList[$_.IDX] })
  
  $TaskName = Switch ($Server)
                  {
                      'Primary' {'SolarWinds_App'}
                      'SQL' {'SolarWinds_SQL'}
                      'APE' {'SolarWinds_APE'}
                      'Netflow' {'SolarWinds_Netflow'}
                      'AWE' {'SolarWinds_AWE'}
                  }
  
  Switch ($Server) {
      'Primary' {
      logman import $TaskName -xml "Primary.xml" -y
      logman start $TaskName
      }
  
      'SQL' {
      logman import $TaskName -xml "SQL.xml" -y
      logman start $TaskName
      }
  
      'APE' {
      logman import $TaskName -xml "APE.xml" -y
      logman start $TaskName
      }
  
      'Netflow' {
      logman import $TaskName -xml "Netflow.xml" -y
      logman start $TaskName
      }
  
      'AWE' {
      logman import $TaskName -xml "AWE.xml" -y
      logman start $TaskName
      }
  }
  </code></pre>
  
  <p>Any help would be appreciated :)</p>