2017-05-18 2 views
0

아래 링크에서 PowerShell 스크립트를 다운로드했습니다.PowerShell Remoting 성능 카운터 수집

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Perfmon-0f013da8

나는 로컬 컴퓨터에 있지만 원격 시스템에 문제를 직면하고 성공적으로이 스크립트를 실행 할 수 있어요. 아래 코드를 업데이트했습니다.

(Get-Counter -ComputerName $ComputerName -Counter (Convert-HString -HString $Counter) -SampleInterval 2 -MaxSamples 10).counterSamples 

다음과 같습니다.

(Invoke-Command -ComputerName $ComputerName -ScriptBlock {Get-Counter -Counter (Convert-HString -HString $Counter) -SampleInterval 2 -MaxSamples 10}).counterSamples 

이제 오류가 발생합니다.

The term 'Convert-HString' is not recognized as the name of a cmdlet, function, script file, or operable program. 

답변

1
기능은 이전에 그것이 그것을 실행하려고 할 때로드 있도록 전화에 당신은 당신은 당신의 스크립트 블록의 전체 기능을 붙여 넣기 할 필요가있다. 그것을 실행하려고하는 원격 컴퓨터에 존재하지 않는

. Invoke-Command/다른 컴퓨터에서 PSSession을 사용하는 모든 것이 있으면 해당 컴퓨터의 컨텍스트에서 실행 중입니다. 함수/모듈/변수를 로컬 시스템에로드하면 로컬 시스템에만 존재합니다. 편집

: $Counter 수 있도록 업데이트가 로컬 컴퓨터에 설정하려면, 다음 스크립트 블록을 Invoke-Command-ArgumentList PARAM를 사용하여 매개 변수화하여 -ScriptBlock에 전달

예 :

(Invoke-Command -ComputerName $ComputerName -ScriptBlock { 
    Param 
    (
    [parameter(Mandatory=$false,Position=0)] 
    [String] 
    $Counter 
    ) 
    function Global:Convert-HString {  
     [CmdletBinding()]    
     Param    
     (
      [Parameter(Mandatory = $false, 
       ValueFromPipeline = $true, 
       ValueFromPipelineByPropertyName = $true)] 
      [String]$HString 
     )#End Param 

     Begin { 
      Write-Verbose "Converting Here-String to Array" 
     }#Begin 
     Process { 
      $HString -split "`n" | ForEach-Object { 

       $ComputerName = $_.trim() 
       if ($ComputerName -notmatch "#") { 
        $ComputerName 
       }  


      } 
     }#Process 
     End { 
      # Nothing to do here. 
     }#End 

    }#Convert-HString 
    Get-Counter -Counter (Convert-HString -HString $Counter) -SampleInterval 2 -MaxSamples 10 
} -ArgumentList $Counter).counterSamples 
+0

하는 것은 귀하가 제공시겠습니까 예. –

+0

이 링크에서 스크립트를 다운로드하고 scriptblock이 호출하려고하기 전에 호출하려는 함수를 스크립트 블록에 붙여 넣었습니다 –

+0

위 코드를 사용하는 중에 오류가 발생합니다. 필수 인수가 누락되었거나 올바르지 않습니다. + CategoryInfo : InvalidResult : (:) [가져 오기 - 카운터, 예외 + FullyQualifiedErrorId : CounterApiError, Microsoft.PowerShell.Commands.GetCounterCommand +에는 PsComputerName : 전화가 오기-카운터가 같은 잘못된 것이 서버 1 –