title: Powershell array scope; why is my array empty?
body: <p>I want to have an array and add elements to it from different functions in my script. My example below illustrates where I might be misunderstanding something regarding scope. My understanding currently is that if an array is defined outside the function, and then elements are added inside the function, those elements should be available outside the function.</p>
  
  <pre><code>Function ListRunningServices
  {
      $services+= Get-Service | ?{$_.Status -eq "Running"} | sort Name | select Name;
  }
  
  $services = @();
  ListRunningServices;
  $services;
  </code></pre>
  
  <p>What am I missing here? Perhaps my style is completely wrong. </p>