我正在尝试直到制作PS脚本,直到从.csv fil创建多个文件夹。 它给了我一些问题
这是我的代码
$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
}
}
这是我的错误
在C:\ Scripts \ CreateMultipleFoldersWithCheck.ps1:5 char:45 + If(!(Test-Path $ Folder.Path \ $ Folder.Folder)) +〜在If(条件)之后丢失语句块。在 C:\ Scripts \ CreateMultipleFoldersWithCheck.ps1:9 char:3 +} +〜表达式或语句中的意外标记'}'。在C:\ Scripts \ CreateMultipleFoldersWithCheck.ps1:14 char:1 +} +〜表达式或语句中的意外标记'}'。 + CategoryInfo:ParserError:(:) [],ParseException + FullyQualifiedErrorId:MissingStatementBlock
我错过了什么?
答案 0 :(得分:-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
}
}
您正在关闭if statement
而不是打开它,这是您的固定脚本。