Link to home
Start Free TrialLog in
Avatar of SAM IT
SAM IT

asked on

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

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
}
Avatar of Rajul Raj
Rajul Raj
Flag of United Arab Emirates image

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

Avatar of SAM IT
SAM IT

ASKER

I have initiated given error getting error. error message screen shot attached
errorfolder.jpg
Avatar of Bill Prew
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
Avatar of SAM IT

ASKER

Again getting same error. attached
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
Can you also show here what the CSV looks like.

~bp
Avatar of SAM IT

ASKER

getting different error now . attached

CSV format also attached
csvformat.jpg
error1.jpg
Please attach the actual CSV file, not a picture of it opened as a spreadsheet, need to see the text file.

~bp
Avatar of SAM IT

ASKER

CSV attached
project.csv
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM IT

ASKER

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
Sounds like a new question, and be sure to include the "Active Directory" topic when you create it.

~bp
Avatar of SAM IT

ASKER

quick  response and resolution