Need to create Multiple folders by importing CSV file  using powershell.

SAM IT
SAM IT used Ask the Experts™
on
Need to create Multiple folders by importing CSV file  using powershell.  Below script is giving error in last line of script can any one help whats working in this script , please assist
____________________________________________________________________

$rows=Import-Csv 'C:\Users\Narasimha.s\Desktop\foldertest\project.csv'
foreach ($row in $rows) {
  $folderName = $row.DisplayName
  md -Path C:\$folderName
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Rajul RajInformation Security Officer

Commented:
Use this Script

Set-Location "c:\data\groups" 
 
$Folders = Import-Csv c:\scripts\GroupdOnTRG.csv 
 
ForEach ($Folder in $Folders) { 
 
New-Item $Folder.Name -type directory 
} 

Open in new window

SAM ITAD windows Admin  

Author

Commented:
I have initiated given error getting error. error message screen shot attached
errorfolder.jpg
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Try:

Set-Location "c:\data\groups" 
 
$Folders = Import-Csv c:\scripts\GroupdOnTRG.csv 
 
ForEach ($Folder in $Folders) { 
 
New-Item -path $Folder -type directory 
} 

Open in new window

~bp
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

SAM ITAD windows Admin  

Author

Commented:
Again getting same error. attached
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Unless you don't have the full path in the CSV, just the name of the new folder, in a column headed DisplayName, which I think would then be:

Set-Location "c:\data\groups" 
 
$Folders = Import-Csv c:\scripts\GroupdOnTRG.csv 
 
ForEach ($Folder in $Folders) { 
 
New-Item -name $Folder.DisplayName -type directory 
} 

Open in new window

~bp
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Can you also show here what the CSV looks like.

~bp
SAM ITAD windows Admin  

Author

Commented:
getting different error now . attached

CSV format also attached
csvformat.jpg
error1.jpg
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Please attach the actual CSV file, not a picture of it opened as a spreadsheet, need to see the text file.

~bp
SAM ITAD windows Admin  

Author

Commented:
CSV attached
project.csv
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Add a header line to the CSV, like this:

Name
a
b
c

Open in new window

And then use this script:
Set-Location "c:\data\groups" 
$Folders = Import-Csv c:\scripts\GroupdOnTRG.csv 
ForEach ($Folder in $Folders) { 
  New-Item -name $Folder.Name -type directory 
} 

Open in new window

~bp
SAM ITAD windows Admin  

Author

Commented:
Perfect......

I have one query on this ......

Post creating the folders in the path security group permission has to be apply to created folders

Security Group Name: shr-projectsmodify This Group is part of Active directory. This group permission has to apply on created folders
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Sounds like a new question, and be sure to include the "Active Directory" topic when you create it.

~bp
SAM ITAD windows Admin  

Author

Commented:
quick  response and resolution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial