Announcement

Collapse
No announcement yet.

Create multiple folder if not exists

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create multiple folder if not exists

    I am trying til make a PS script til create multiple folders from a .csv fil.
    It is giving me some problems

    This is my code
    Code:
    $Folders = Import-Csv C:\Scripts\NewFolders\NewFolders.csv
    
    ForEach ($Folder in $Folders)
    {
     If(!(Test-Path $Folder.Path\$Folder.Folder))
      }
      New-Item -ItemType Directory -Force -Path $Folder.Path\$Folder.Folder
      Write-Host Folder $Folder.Folder created in $Folder.Path ! -ForegroundColor Green
      }
     Else
      {
      Write-Host "Folder $Folder.Folder already exists in $Folder.Path !!!" -ForegroundColor Red -BackGroundColor Black
      }
    }
    And this is my error

    Code:
    At C:\Scripts\CreateMultipleFoldersWithCheck.ps1:5 char:45
    +     If(!(Test-Path $Folder.Path\$Folder.Folder))
    +                                                ~
    Missing statement block after If ( condition ).
    At C:\Scripts\CreateMultipleFoldersWithCheck.ps1:9 char:3
    +         }
    +         ~
    Unexpected token '}' in expression or statement.
    At C:\Scripts\CreateMultipleFoldersWithCheck.ps1:14 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : MissingStatementBlock
    What am I missing?

  • #2
    Should be an OPEN curly bracket { after the IF - you are closing a curly bracket }
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment

    Working...
    X