Create folders from a csv file

This is a basic script to create folders from a csv file. It reads teh contents of a file into an array and then does a for each to create the follders. I plan to add set-acl to the script later so I can set permissions.

 
 
 
 
 
4.8 Star
(9)
Add to favorites
Storage
8/3/2011
E-mail Twitter del.icio.us Digg Facebook
  • what about permissions
    1 Posts | Last post July 19, 2017
  • Existing folders
    1 Posts | Last post July 13, 2017
    • What would happen if folders are already existing in the list?
  • Import-Csv : Cannot process argument because the value of argument "name" is invalid.
    1 Posts | Last post February 04, 2013
    • For those of you who might get this error.
      
      Import-Csv : Cannot process argument because the value of argument "name" is invalid.
      
      Try using the -Header parameter in the Import-CSV cmdlet.
      
      I was using a multi column csv file, but it appears that was not the problem, by using the '-Header HEADERNAME' parameter I was able to force the script to only use the column HEADNAME.
      
      other than that, great script John, thanks!
  • Problem with non-english characters
    2 Posts | Last post September 03, 2012
    • Hi there,
      I've used this script and the only problem i have is with folder names that aren't in english. is there any way to include non-english characters?
      thanks!
      Sion
    • Hi,
      
      Save you file as a Unicode file (you can do this in notepad)
      
      I just created a simple file and imported with powershell. You'll get ? with the wrong encoding like this
      
      import-csv T:\encoding.txt
      
      ?
      -
      ?
      ?
      ?
      
      and correctly with the correct encoding ...
      
      import-csv T:\encoding.txt
      
      A
      -
      +
      A
      A
      
      hope that helps :o)
      
      J
      
      
       
  • No question -- just thanks!
    2 Posts | Last post May 08, 2012
    • first off -- thanks, this works great!
      
      did you end up setting permissions as well?
      
      Thanks,
      WBR
    • Hi,
      Just I’ve become quite accustom to settings rights programmatically :o)
      I’ve uploaded a couple fixing rights but these examples require the folder name and user name matching.
      http://gallery.technet.microsoft.com/A-process-which-adds-c860d5b0
      
      http://gallery.technet.microsoft.com/Repair-Profile-Store-076cb750
      I’ll upload some code if I can to dig up the stuff I used to grant read or full from a csv file
      J
      
  • I get a error when running this script
    8 Posts | Last post November 02, 2011
    • I get a error like
      New-Item : Cannot bind argument to parameter 'Path' because it is null.
      At C:\data\groups\test.ps1:10 char:9
      + New-Item <<<<  $Folder.name -type directory
          + CategoryInfo          : InvalidData: (:) [New-Item], ParameterBindingValidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewItemComm
         and
      
      i've put the test.ps1 and thes test.csv in the c:\data\groups dir
    • Hi,
      
      Did you create a root location like "c:\data\groups" ?
      The intention of the script is to create the folder structure benefit the root. The csv file doesn’t need to site in "c:\data\groups".
      
      J
      
    • Yes i've created the root.
      my powershell script ended every time in c:\data\groups so i've put the files there
      
    • Hi,
      I’ve updated the sample code and csv file contents. In $Folder.FolderName the “.FolderName” references the column name from the csv file.
      Hopefully you should find the code works now.
      Kind Regards,
      John
      
    • Hey John,
      
      I copy your command but I get this error "New-Item : Cannot bind argument to parameter 'Path' because it is null." my csv file has a header name folder and I created the folder c:\data\groups
      
      Any idea why is doing this? 
    • Yes sorry .. I updated the code but didn't update the sample csv. I've uploaded again and the code should work, sorry.
    • You could also try something like this if you are still in the market. 
      
      $Users = "D:\userfolders.csv"
      import-csv $users |
      where {
      $newPath = Join-Path "\\computer\folder1\folder2" -childpath $user 
      New-Item $_.Name -type directory
      }
      
      notice $_.Name = This is the "header" for the excel document. I also use $_.sAMAccountName sometimes because I use CSV\powershell combos that do things to user accounts as well and name wouldn't be the right header.  
    • This might looks better...
      
      
      
      $Users = "D:\myusers\drives.csv"
      import-csv $users |
      where {
      $newPath = Join-Path "\\it-mitchchr\d$\myusers" -childpath $user
      New-Item $_.Name -type directory
      }
      
  • How does $Folder get set?
    2 Posts | Last post September 02, 2010
    • How does it know the values for $Folder?  I get that it's coming from the csv but is there a label for the row or column?
    • Yes that's correct.