title: Cannot index into a null array on assignment?
body: <p>all.</p>
  
  <p>About to lose it - This was working hours ago.</p>
  
  <p>So when I run this I get</p>
  
  <pre><code>Cannot index into a null array.
  At line:3 char:15
  + $backlog[0]=$(Get-DFSRBacklog -sourcecomputername:ts-fileshares2 -destinationcom ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
  </code></pre>
  
  <p>Issue being, when I search here and elsewhere, I find people making issues assigning a null array TO a variable. Not assigning to the array.</p>
  
  <p>Below is most of the code (I am running this against multiple fileshares, too lazy to change server names in six lines. Typically backlog[] contains 6 sets of replies.</p>
  
  <pre><code>clear-host
  $backlog[0]=$(Get-DFSRBacklog -sourcecomputername:a -destinationcomputername:b -Verbose) 4&gt;&amp;1
  
  #$collection is one array result. This will be easier to split out into by-server later.
  [int]$total = 0
  foreach ($collection in $backlog)
  {
      $collection | ForEach-Object -Process {
          if ($_.getType().FullName.equals("System.Management.Automation.VerboseRecord"))
          {
              #$_ | Get-Member
              #Write-Host $_.Message
              if ($_.Message -like "*has a backlog*")
              {
                  #testing write-host $_.Message.split(" ")[12]
                  $total += [convert]::ToInt32($_.Message.split(" ")[12],10)
              }
          }
      }
  }
  #testing Write-Host $total
  [Environment]::SetEnvironmentVariable("TOTALFILESHAREBACKLOG",$total, "Machine")
  #testing Write-Host $env:TOTALFILESHAREBACKLOG
  </code></pre>
  
  <p>As I said, this was working hours ago. Not sure if I have some weird variable stuck, but this is on out prod server (no way to get DFSR backlog from a non-prod server) so I don't want to reboot the entire server.</p>
  
  <p>This is a signed powershell script that is running on a schedule (zabbix pulls the env variable later for reporting) but that shouldn't affect it. The only thing that I changed between this working and not working was moving where this file was saved.</p>
  
  <p>The Powershell Get-DFSRBacklog does always return a value or print an error, so that's not it.</p>
  
  <p>Even doing $backlog[0] = 1 throws an error.</p>
  
  <p>P.P.S. </p>
  
  <pre><code>Name                           Value                                                                                 
  ----                           -----                                                                                 
  PSVersion                      4.0                                                                                   
  WSManStackVersion              3.0                                                                                   
  SerializationVersion           1.1.0.1                                                                               
  CLRVersion                     4.0.30319.42000                                                                       
  BuildVersion                   6.3.9600.17400                                                                        
  PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                                                                  
  PSRemotingProtocolVersion      2.2 
  </code></pre>