2016-09-08 6 views
-1

Ich versuche, ein PS-Skript zu erstellen, mehrere Ordner von einem .csv-Fil erstellen. Es gibt mir einige ProblemeErstellen Sie mehrere Ordner, wenn nicht existiert

Dies ist mein 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 
    } 
} 

Und das ist mein Fehler

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

Was bin ich?

+0

Unmittelbar nach der If-Anweisung Sie eine Schließung haben}, anstatt eine Öffnung { – Eilidh

+0

Ändern Sie den falschen} auf eine {für den Anfang :) – Eilidh

Antwort

-1
$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 
    } 
} 

Sie schließen if statement istead es zu öffnen, hier ist Ihr Festschrift.

+0

'$ Folders = Import-Csv C: \ Scripts \ Csv \ NewFolders.csv foreach ($ Ordner in $ Folders) { $ Pathname = $ Folder.'Path ' $ Folder = $ Folder.'Folder' \t if (! (Test-Path $ Pathname \ $ Ordnername)) \t \t { \t \t New-Item -Pfad $ Pfadname \ $ Ordnername -ItemType Directory -Force \t \t Write-Host "$ Ordnername erstellt in $ Pfadname!" -foregroundcolor Grün \t \t} \t Else \t \t { \t \t Write-Host "Ordner $ Ordnername existiert bereits in $ Pathname !!!" -ForegroundColor Rot -BackGroundColor Schwarz \t \t} } ' Ich reparierte das Skript mit diesem Code. Aber danke für die Hilfe. – Webnoob

Verwandte Themen