2016-12-13 6 views
0

PowerShell의 스크립트를 사용하여 여러 NAS 상자의 모든 폴더를 반복적으로 통과하여 전체 경로가있는 모든 폴더를 Out-File에 표시합니다. Get-FolderEntry 스크립트를 사용하여 here을 찾았습니다.스크립트에서 시작 작업 사용

파일 이름/경로 길이에 260 개 이상의 문자가있는 다중 NAS 상자가 있기 때문에 멀티 스레딩을 사용하여 프로세스 속도를 높일 수 있습니다.

코드 : 지금까지

. C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1 
# list with the servers 
$Computers = Get-Content C:\Users\mdevogea\Desktop\servers.txt 

# scriptblock calling on get-FolderEntry 
$sb = { 
    param ($Computer, $fname) 
    C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1 -Path $Computer | 
     fl | Out-File -Append -Width 1000 -FilePath $fname 
} 

foreach($Computer in $Computers) 
{ 
    $name = $Computer.Replace("\", "") 
    $fname = $("C:\Users\mdevogea\Desktop\" + $name + ".txt") 
    #Get-FolderEntry -Path $Computer | fl | Out-File -Append -Width 1000 $fname 

    $res = Start-Job $sb -ArgumentList $Computer, $fname 
} 

# Wait for all jobs 
Get-Job 
while(Get-Job -State "Running") 
{ 
    Write-Host "Running..." 
    Start-Sleep 2 
} 
# Get all job results 
Get-Job | Receive-Job | Out-GridView 

:

  1. 내가 중 하나는 파일의 정확한 이름과 빈 파일을 얻을.

  2. Get-FolderEntry 코드와 함께 올바른 이름의 파일이 생성됩니다.

  3. 내가 스크립트 블록에 전달한 내용에 따라 오류가 발생합니다.

간단히 말해서, 어리석은 일이지만 그것을 보지 못합니다.

+0

scriptblock에서 먼저 * script *'Get-FolderEntry.ps1'을 점령 한 다음 * function *'Get-FolderEntry'를 호출합니다. 그게 당신이 오류를 보여주는 데 도움이되지 않는다면. –

+0

다음과 같은 뜻으로 가정합니다. $ sb = {. C : \ Users \ mdevogea \ Downloads \ Get-FolderEntry.ps1 param ($ Computer, $ fname) C : \ Users \ mdevogea \ Downloads \ Get-FolderEntry.ps1 -Path $ 컴퓨터 | 플로리다 | 아웃 - 파일 -append - 폭 1000 -FilePath의 $의 FNAME } 그래서 다음이 오류가있는 경우 : 는 널 (null)이기 때문에 '파일 경로를'매개 변수 인수를 결합 할 수 없습니다. + CategoryInfo : InvalidData : (:) [아웃 파일] ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed, Microsoft.PowerShell.Commands.OutFileCommand +에는 PsComputerName : – Michael

+0

로컬 호스트은'파람()'문을 먼저해야합니다. 그런 다음 점 - 소스. 그리고 당신은 여전히 ​​함수 * 대신 스크립트 *를 실행하고 있습니다. –

답변

0

는 결국 자신 이후에 발견 된 일부 시행 착오 : 내 올바른 방향으로 가리키는 대한

. C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1 
# list with the servers 
$Computers = Get-Content C:\Users\mdevogea\Desktop\servers.txt 

# scriptblock calling on get-FolderEntry 
$sb = { 
    Param ($Computer, $fname) 
    . C:\Users\mdevogea\Downloads\Get-FolderEntry.ps1 
    (Get-FolderEntry -Path $Computer | fl | Out-File -Append -Width 1000 -FilePath $fname) 
} 

foreach ($Computer in $Computers) 
{ 
    $name = $Computer.Replace("\", "") 
    $fname = $("C:\Users\mdevogea\Desktop\" + $name + ".txt") 
    $res = Start-Job $sb -ArgumentList $Computer, $fname 
} 

# Wait for all jobs 
Get-Job 
while (Get-Job -State "Running") 
{ 
    Write-Host "Running..." 
    Start-Sleep 2 
} 
# Get all job results 
Get-Job | Receive-Job | Out-GridView 

덕분에 많은 안스를!