title: Powershell: get-childitem folder from csv
body: <p>I'm trying to get the results of a Get-ChildItem to filter a list of these folders from a CSV</p>
  
  <p>I have a number of homefolders that are named the same as the users SamAccountName (as is usual)</p>
  
  <p>all the home folders are stored on my share:
  \DomainName\Users</p>
  
  <p>My CSV contains the users which are names the same as the home folders
  Example:</p>
  
  <pre><code>SamAccountName
  123456
  123457
  123458
  </code></pre>
  
  <p>The part of my script that I want to work goes like this:</p>
  
  <pre><code>$SAM = import-csv "C:\Scripts\HomeDrive.csv"
  $HomeDriveSharePath = "\\Domain\users"
  $HomeDirectories = Get-ChildItem $HomeDriveSharePath | Where {$_.Name -Match $SAM.samaccountname -AND $_.PsIsContainer -eq $true}
  </code></pre>
  
  <p>With my CSV this returns no results (although the folder for the example users in the CSV definitely exists)</p>
  
  <p>If I run this, it returns all of the homefolders (as it should)</p>
  
  <pre><code>Get-ChildItem $HomeDriveSharePath
  </code></pre>
  
  <p>If I run this:</p>
  
  <pre><code>$HomeDirectories = Get-ChildItem $HomeDriveSharePath | Where {$_.Name -Match "123456" -AND $_.PsIsContainer -eq $true}
  </code></pre>
  
  <p>then I do get the corresponding folder displayed (proving the line kind of works and the folder does exist)</p>
  
  <p>This needs to be run for hundreds of users with regards to a migration, Otherwise I'd just sit here doing it manually :-(</p>
  
  <p>First time posting, apologies if this isn't formatted or explained quite right... a thorough search of this site and Google hasn't brought back the exact scenario I seem to have.</p>
  
  <p>I'm quite stumped... your help appreciated,</p>
  
  <p>Thanks</p>