title: Powershell Script reading file into array
body: <p>I have a script I'm working on. I want it to read in a column named ComputerName and one named UserName.</p>
  
  <p>My CSV file looks like this:</p>
  
  <pre><code>ComputerName | Username
  computer01   | user1
  computer02   | user2
  </code></pre>
  
  <p>The Pipes are representing cells in excel. </p>
  
  <p>Here's my script:</p>
  
  <pre><code>$computerName = @()
  $userName = @()
  
  Import-Csv C:\test\script\Computername_username_test.csv -Delimiter "|" |`
      ForEach-Object
          {
              $computerName += $_.ComputerName
              $userName += $_.UserName
          }
  
  $destination = New-Item -ItemType Directory -Path C:\test\$userName\dictionary_Files\ -force
  $fileList = Get-WmiObject -Class CIM_DataFile -Filter "Drive='C:' And Extension='dic'" -Computername $computerName
  
  foreach ($file in $fileList)
  {
      $drive, $path = $file.Name.Split('\',2)
      $drive = $drive -replace ':','$'
      $remoteFile = "\\$computerName\$drive\$path"
      Write-Verbose "Copy $remoteFile to $destination"
      Copy-Item $remoteFile -Destination $destination -Confirm
  }
  </code></pre>
  
  <p>My goal is to search the C drive of the remote computer for all files with the .dic extension and copy them to a location inside a folder that is named the same as their username from the excel sheet.</p>
  
  <p>When I run this I'm getting the following:</p>
  
  <pre><code>PS C:\Test\Script&gt; C:\Test\Script\DicFiles03_importCSV.ps1
  cmdlet ForEach-Object at command pipeline position 2
  Supply values for the following parameters:
  Process[0]: 
  
              $computerName += $_.ComputerName
              $userName += $_.UserName
  
  Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null, empty, or an element of the argument 
  collection contains a null value. Supply a collection that does not contain any null values and then try the command again.
  At C:\Test\Script\DicFiles03_importCSV.ps1:13 char:102
  + ...  -Filter "Drive='C:' And Extension='dic'" -Computername $computerName
  +                                                             ~~~~~~~~~~~~~
      + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  </code></pre>
  
  <p>Thank you for your help.</p>