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
}
PowershellScripting LanguagesWindows Server 2008

Avatar of undefined
Last Comment
SAM IT

8/22/2022 - Mon
Rajul Raj

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 IT

ASKER
I have initiated given error getting error. error message screen shot attached
errorfolder.jpg
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SAM IT

ASKER
Again getting same error. attached
Bill Prew

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 Prew

Can you also show here what the CSV looks like.

~bp
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SAM IT

ASKER
getting different error now . attached

CSV format also attached
csvformat.jpg
error1.jpg
Bill Prew

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

~bp
SAM IT

ASKER
CSV attached
project.csv
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
Bill Prew

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

~bp
SAM IT

ASKER
quick  response and resolution
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.