전경에서 시스템에 '로드'를 적용하면서 PowerShell 백그라운드 작업에서 성능 데이터를 수집하려고합니다. -ComputerName 매개 변수없이 Get-Counter/Export-Counter 스크립트를 백그라운드 작업으로 실행하면 로컬 컴퓨터의 성능 데이터가있는 출력 파일이 예상대로 만들어집니다. 나는 -ComputerName 매개 변수를 포함하고, 전경 스크립트 블록을 실행하면Powershell Background Job - 'ComputerName'매개 변수를 사용하여 Export-Counter/Get-Counter에서 출력을 얻으려면 어떻게해야합니까?
# Background job, No ComputerName
$scriptBlockStr = "Get-Counter -Counter ""\Memory\Available MBytes"" -SampleInterval 2 -MaxSamples 3 | Export-Counter -Force -FileFormat CSV -Path $PSScriptRoot\MinPerfTest.csv"
$sb = [scriptblock]::Create($ScriptBlockStr)
$j = Start-Job -Name "PerfMon01" -ScriptBlock $sb
Start-Sleep -Seconds 10
Stop-Job $j.Id
Write-Host "See $PSScriptRoot\MinPerfTest.csv."
, 그것은 지정된 컴퓨터에서 성능 데이터와 출력 파일을 생성합니다. 나는 -ComputerName 매개 변수를 사용하여 스크립트를 실행하는 경우
# Foreground job, With ComputerName
$scriptBlockStr = "Get-Counter -Counter ""\Memory\Available MBytes"" -ComputerName ""\\CPQDEV.fpx.com"" -SampleInterval 2 -MaxSamples 3 | Export-Counter -Force -FileFormat CSV -Path $PSScriptRoot\MinPerfTest.csv"
$sb = [scriptblock]::Create($ScriptBlockStr)
& $sb
Write-Host "See $PSScriptRoot\MinPerfTest.csv. (Wait! It can take a while.)"
는하지만, 백그라운드 작업으로 내보내기 - 카운터 cmdlet은 결코 어떤 출력을 생성하지 않습니다.
# Background job, With ComputerName
$scriptBlockStr = "Get-Counter -Counter ""\Memory\Available MBytes"" -ComputerName ""\\CPQDEV.fpx.com"" -SampleInterval 2 -MaxSamples 3 | Export-Counter -Force -FileFormat CSV -Path $PSScriptRoot\MinPerfTest.csv"
$sb = [scriptblock]::Create($ScriptBlockStr)
$j = Start-Job -Name "PerfMon01" -ScriptBlock $sb
Start-Sleep -Seconds 10
Stop-Job $j.Id
Write-Host "See $PSScriptRoot\MinPerfTest.csv. (Wait! It could take a while, if it works at all.)"
이름이 지정된 컴퓨터에서 성능 데이터를 얻으려면 어떻게해야합니까? 감사합니다.
대상 컴퓨터에 디렉터리 구조가 있습니까? 그것은 아마도 오류를 던지고 있습니다. 작업의 출력을 작업에서 검색하십시오. – TheIncorrigible1
'Stop-Job'을 사용하지 마십시오. [Receive-Job -Wait 사용] (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/receive-job?view=powershell-5.1) –
확장하려면 당신의 제안 @BaconBits :'$ j = 시작 - 작업 - 이름 "PerfMon01"-ScriptBlock $ sb | Receive-Job -Wait' – TheIncorrigible1