title: PowerShell script to create folders and then modify creation date from csv
body: <p>I would like to create a PowerShell script that can import a CSV file (details.csv) with two headers (FileName and FileCreationTime). Ideally, the script would look for details.csv in the current location the script is saved.</p>
  
  <p>It would create folders in the script's current location with the same name as FileName, and the creation date of said folder would then be changed to match FileCreationTime.   </p>
  
  <p>Example chunk of my CSV [made in A &amp; B columns of Excel then saved as CSV (comma delimited)(*.csv)]:</p>
  
  <pre>
  FileName    FileCreationTime
  Alpha       5/17/2017
  Bravo       12/23/2013
  Charlie     11/8/2015
  </pre>
  
  <p>I have been searching for a solution, but nothing I do seems to be quite right. I currently have this:</p>
  
  <pre><code>Import-Csv -Path 'K:\Users\eschlitz\Thesis\details.csv' -Delimiter "," |
      ForEach-Object { 
          $path = 'K:\Users\eschlitz\Thesis'
          # Again, didn't want a definite path here, but I was trying different
          # tweaks to see if I could get at least one instance to work correctly.
          New-Item -Path $path -Name $$_.Filename -Type Directory
          (Get-Item $_.Filename).CreationTime = (Get-Date $_.FileCreationTime) 
      }
  </code></pre>
  
  <p>My current error message:</p>
  
  <blockquote>
    <p>Get-Item : Cannot find path 'K:\Users\eschlitz\Thesis\Alpha' because it does not exist.</p>
  </blockquote>
  
  <p>I do not care about whether or not the hh:mm:ss part of the creation time is edited for the new folders, but it would be a bonus if I could standardize them all to 12:00:00 AM. </p>
  
  <p>~~~~~~~~~~~~~~~~~~~~~~~Question Duplication Edit~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Suggested edit to show how my question is different from <a href="https://stackoverflow.com/questions/38959250/powershell-change-the-timestamp-date-created-of-a-folder-or-file">PowerShell: Change the timestamp (Date created) of a folder or file</a></p>
  
  <p>Everything that I was able to find related to this did either only A)create folders from a CSV, or was B)script to edit the creation date of a single folder / or batch edit the creation date of multiple folders but only with a single new creation time. I wanted the script to hopefully fail if it would be unable to correctly find the new creation time unique to each new folder, thereby eliminating the need for me to manually delete wrong folders or edit the creation time manually.</p>
  
  <p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Edit~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Just wanted to post the complete, working versions in case anyone needs them in the future.</p>
  
  <pre><code>#Adds folders to specified directory and modifies their creation date
  Import-Csv -Path 'K:\Users\eschlitz\Thesis\details.csv' -Delimiter "," |
      ForEach-Object {
          $path = ' K:\Users\eschlitz\Thesis'
          $dir = New-Item -Path $path -Name $_.Filename -Type Directory
          $dir.CreationTime = [DateTime]::ParseExact($_.FileCreationTime, 
          'M\/d\/yyyy', [Globalization.CultureInfo]::InvariantCulture)
  } 
  </code></pre>
  
  <p>And a slightly different version depending on needs:</p>
  
  <pre><code>#Adds folders and then modifies their creation date where script+csv 
  #currently are 
  Set-Location -Path "$PSScriptRoot"
  Import-Csv -Path ".\details.csv" -Delimiter ',' |
      ForEach-Object {
          New-Item -Path "$PSScriptRoot" -Name $_.FileName -Type Directory
          (Get-Item $_.Filename).CreationTime = 
          ([DateTime]::ParseExact($_.FileCreationTime, 'M\/d\/yyyy', 
          [Globalization.CultureInfo]::InvariantCulture))
  } 
  </code></pre>