2014-09-04 4 views
0

폴더를 만들 : 그것에 I 파이프 여러 폴더 이름이 때기능이이 파이프 여러 폴더를 만들 잘 작동

Function Add-Folders { 

    $Permissions.Folder | ForEach-Object { 

     if (Test-Path "$Path\$_" -PathType Container) { 
      Write-Verbose "-Exists: $Path\$_" 
     } 
     else { 
      New-Item "$Path\$_" -Type Directory > $null 
      Write-Verbose "-Created: $Path\$_" 
     } 
    } 
} 

이 하나가 작동하지 않습니다 디버그 모드에서 $NamePermissions.Folder에서 사용할 수있는 마지막 폴더 이름 만 수신한다는 것을 알 수 있습니다. 나는 왜 그것이 모든 것을 연결하고 있지 않은지 정말로 이해하지 못합니다. 아마 여기서 명백한 것을 놓치고있을 것입니다.

답변

1

내가 Process 섹션을 잃어버린 나의 바보 같은 실수를 수정 :

Function Make-Folders { 
    [CmdletBinding(SupportsShouldProcess=$True)] 
    Param(
     [parameter(Mandatory=$true,Position=0)] 
     [ValidateScript({Test-Path $_ -PathType Container})] 
     [ValidateNotNullOrEmpty()] 
     [String]$Path, 
     [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1)] 
     [ValidateNotNullOrEmpty()] 
     [String[]]$Name 
    ) 
    Process { 

     $Name | ForEach-Object { 

      if (Test-Path "$Path\$_" -PathType Container) { 
       Write-Verbose "-Exists: $Path\$_" 
      } 
      else { 
       New-Item "$Path\$_" -Type Directory > $null 
       Write-Verbose "-Created: $Path\$_" 
      } 
     } 
    } 
} 


$Permissions.Folder | Make-Folders -Path $Target -Verbose 

미안 얘들 아, 내 나쁜.