title: Cannot Index Into Null Array error
body: <p>I am trying to get a PowerShell Script to work but I am running into a error. The error is,</p>
  
  <pre>
  Cannot index into a null array.
  At C:\users\cody\desktop\test.ps1:18 char:97
  +     $Profiles += (netsh wlan show profiles) | Select-String "\:(.+)$" | Foreach {$_.Matches.Groups[ &lt;&lt;&lt;&lt; 1].Value.Trim()} | Sort-Object
      + CategoryInfo          : InvalidOperation: (1:Int32) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
  </pre>
  
  <p>I am not sure exactly what the fix would be for this.</p>
  
  <p>The script is:</p>
  
  <pre><code>#Create QuestionBox
  $title = "Reveal WiFi network password"
  $message = "Do you want to reveal all or just one WiFi password stored on this computer?"
  $All = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;All", "Reveal all stored WiFi Passwords"
  $One = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;One", "Reveal only a selected stored WiFi Password"
  $ShowWiFiProfiles = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;Show WiFi Profiles", "Only Display stored Wifi Profiles on this computer"
  $options = [System.Management.Automation.Host.ChoiceDescription[]]($All, $One, $ShowWiFiProfiles )
  $result = $Host.UI.PromptForChoice($title, $message, $options, 0) 
  
  #Get all WiFi Profiles
  $Profiles = @()
  $Profiles += (netsh wlan show profiles) | Select-String "\:(.+)$" | Foreach{$_.Matches.Groups[1].Value.Trim()} | Sort-Object
  
  #Read out the user input
  switch ($result) {
      0 {
          #The user selected All
          $Profiles | Foreach{$ProfileName = $_; (netsh wlan show profile name="$_" key=clear)} | `
              Select-String "Key Content\W+\:(.+)$" | `
              Foreach{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | `
              Foreach{[PSCustomObject]@{ PROFILE_NAME=$ProfileName;PASSWORD=$pass }} | `
              Format-Table -AutoSize
      }
      1 {
          #The user selected One
          $Wifi2Reveal = Read-Host "Name of the WiFi profile you wish to reveal"
          (netsh wlan show profile name="$Wifi2Reveal" key=clear)| `
              Select-String "Key Content\W+\:(.+)$" | `
              Foreach{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | `
              Foreach{[PSCustomObject]@{ PROFILE_NAME=$Wifi2Reveal;PASSWORD=$pass }} | `
              Format-Table -AutoSize 
      }
      2 {
          #The user selected Only Show Wifi profiles
          $Profiles 
      }
  }
  </code></pre>