title: Extract Data to CSV but only need first 4 characters - Powershell
body: <p>I currently have a PS script to pull all folder names in a directory and put them into a CSV. This works perfectly. Now I need to extract the same folder names but only have the first 4 characters in the column. Here is my current script:</p>
  
  <pre><code>get-childitem $Path -directory | select-object NAME | export-excel -tablename "Projects" -path c:\archive_$date.xlsx
  </code></pre>
  
  <p>It dumps the data that I need, but the current format is 0123-XXXXXXXX. I need to remove everything to the right of the "-" (and in some cases it is an underscore). I found something to add to the script but unfortunately its not working - <code>$Name.Substring(0, [Math]::Min($Name.Length, 4))</code></p>