How to Create Folders from a CSV file by Using PowerShell

Here is a sample csv file with a title called “Organizations”. 

sample csv file

Below, please see the scripts

#Crated by Summa, 2024-10-23

 

$file= “C:\Temp\folders.csv”

if (Test-Path $file) {

    $item=Get-Item $file

    Write-Output “The csv file exists. Details:”

    $item

} else {

    Write-Output “The csv file does not exist.”

}

$folderlist = Import-Csv $file

$rootpath = “C:\Sample Folder\”

foreach ($folder in $folderlist){

    $path = join-path -path $rootpath -childpath $folder.Organizations;

    if (-not (Test-Path -Path $path)) {

        # Create the folder

    new-item -type directory -path $path;

            Write-Output “Created folder: $path”

    } else {

        Write-Output “Folder already exists: $path”

    }