Powershell - 리소스 부족으로 인해 테스트-연결 실패
리소스 부족 오류와 함께 테스트 연결이 간헐적으로 실패함:
test-connection : Testing connection to computer 'SOMESERVER' failed: Error due to lack of resources
At line:1 char:45
+ ... ($server in $ServersNonProd.Name) { test-connection $server -Count 1}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SOMESERVER:String) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand
따라서 루프에서 컴퓨터 목록을 테스트해야 하는 경우에는 신뢰할 수 없고 유용하지 않습니다.이 기능을 안정적으로 사용할 수 있는 해결 방법, 대안 또는 해결 방법이 있습니까?
이 솔루션은 현재 제 솔루션이지만, 여전히 충분히 신뢰할 수 없으며(때로는 5회 연속 실패하기도 합니다), 모든 지연과 재시도로 인해 시간이 오래 걸립니다.
$Servers = Import-CSV -Path C:\Temp\Servers.csv
$result = foreach ($Name in $Servers.FQDN) {
$IP = $null
if ( Resolve-DNSName $Name -ErrorAction SilentlyContinue ) {
$IP = (Test-Connection -Count 1 -ComputerName $Name -ErrorAction SilentlyContinue).IPv4Address
if ( $IP -eq $null ) {
Start-Sleep -Milliseconds 100
$IP = (Test-Connection -Count 1 -ComputerName $Name -ErrorAction SilentlyContinue).IPv4Address
}
if ( $IP -eq $null ) {
Start-Sleep -Milliseconds 200
$IP = (Test-Connection -Count 1 -ComputerName $Name -ErrorAction SilentlyContinue).IPv4Address
}
if ( $IP -eq $null ) {
Start-Sleep -Milliseconds 300
$IP = (Test-Connection -Count 1 -ComputerName $Name -ErrorAction SilentlyContinue).IPv4Address
}
if ( $IP -eq $null ) {
Start-Sleep -Milliseconds 400
$IP = (Test-Connection -Count 1 -ComputerName $Name -ErrorAction SilentlyContinue).IPv4Address
}
}
new-object psobject -Property @{FQDN = $Name; "IP Address" = $IP}
}
일반 ping(ping.exe)은 매번 작동하므로 파워셸(호스트의 가동 또는 정지, IP가 응답하는 것)로 구문 분석할 수 있는 좋은 방법이 있다면 이상적인 해결책인 것 같습니다. 하지만 저는 작동하는 무언가가 필요하기 때문에 아이디어에 개방적입니다.
PowerShell의에서는 PowerShell을 하십시오.-Quiet
합니다.Test-Connection
항상 돌아오는 것처럼 보입니다.True
또는False
이전 버전에서는 일관되게 작동하지 않는 것 같았지만, 지금은 다른 작업을 수행하고 있거나 개선된 상태입니다.
$Ping = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
하지만 최근에는 단순히 네트워크를 사용할 수 없을 때 테스트하지 않았습니다.
이전 답변:
Test-Connection
DNS가 주소로 응답하지 않거나 네트워크를 사용할 수 없을 때 응답하지 않습니다.즉, cmdlet이 ping을 전혀 전송할 수 없다고 판단하면 트랩하거나 무시하기 어려운 불쾌한 방식으로 오류가 발생합니다.Test-Connection
DNS가 이름을 주소로 확인하고 네트워크가 항상 존재함을 보장할 수 있는 경우에만 유용합니다.
CIM Ping(Powershell v3+)을 사용하는 경향이 있습니다.
$Ping2 = Get-CimInstance -ClassName Win32_PingStatus -Filter "Address='$ComputerName' AND Timeout=1000";
또는 WMI ping(Powershell v1 또는 v2):
$Ping = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$ComputerName' AND Timeout=1000";
둘 중 하나는 기본적으로 동일하지만 사물에 대해 약간 다른 형식을 반환합니다.:Get-WmiObject
에는 Powershell v6에서 할 수 때문입니다.Get-CimInstance
그것을 대체하도록 설계되었습니다.
여기서 가장 큰 단점은 상태 코드를 직접 해결해야 한다는 것입니다.
$StatusCodes = @{
[uint32]0 = 'Success';
[uint32]11001 = 'Buffer Too Small';
[uint32]11002 = 'Destination Net Unreachable';
[uint32]11003 = 'Destination Host Unreachable';
[uint32]11004 = 'Destination Protocol Unreachable';
[uint32]11005 = 'Destination Port Unreachable';
[uint32]11006 = 'No Resources';
[uint32]11007 = 'Bad Option';
[uint32]11008 = 'Hardware Error';
[uint32]11009 = 'Packet Too Big';
[uint32]11010 = 'Request Timed Out';
[uint32]11011 = 'Bad Request';
[uint32]11012 = 'Bad Route';
[uint32]11013 = 'TimeToLive Expired Transit';
[uint32]11014 = 'TimeToLive Expired Reassembly';
[uint32]11015 = 'Parameter Problem';
[uint32]11016 = 'Source Quench';
[uint32]11017 = 'Option Too Big';
[uint32]11018 = 'Bad Destination';
[uint32]11032 = 'Negotiating IPSEC';
[uint32]11050 = 'General Failure'
};
$StatusCodes[$Ping.StatusCode];
$StatusCodes[$Ping2.StatusCode];
대신에, 저는 사용했습니다.@BenH와 같은 Net Ping도 설명했는데, 이는 여러분에게 많은 도움이 됩니다.WMI와 CIM에 유리하게 사용을 중단한 이유가 있었는데, 그 이유가 무엇이었는지 더 이상 기억이 나지 않습니다.
나는 그것을 사용하는 것에 편애합니다.NetPing 클래스가 아닌Test-Connection
$Timeout = 100
$Ping = New-Object System.Net.NetworkInformation.Ping
$Response = $Ping.Send($Name,$Timeout)
$Response.Status
TTL/Fragmentation을 설정해야 하는 경우 Send 메서드에서 추가 파라미터를 사용할 수 있습니다.또한 타임아웃은 밀리초 단위이며 $name만 사용하면 타임아웃이 5초라고 생각하는데, 이는 일반적으로 너무 깁니다.
Windows IP Helper는 IP_REQ_TIMED_OUT 오류를 값 11010으로 정의합니다. 이 값은 Windows 시스템 오류 WSA_QOS_ADMISSION_FAILURE 11010 '리소스 부족으로 인한 오류'와 동일하므로 문제의 경우 실제로 수신된 오류가 타임아웃 오류이며 단순히 '리소스 부족'으로 잘못 해석되었을 가능성이 높습니다.
테스트 연결에 -computername을 포함하면 (어쨌든 5.x에서) 이 오류가 나타납니다.그것을 제거하면 작동합니다.ping과 test-connection을 비교하여 ICMP는 test-connection이 win32_pingstatus 명령에 해당하는 윈도우즈 방화벽에서 기본적으로 차단됩니다.WMI는 기본적으로 차단되지 않습니다.그러나 시스템의 WMI 저장소가 정상이 아니거나 fw에 의해 차단된 경우에는 당연히 실패합니다.
powershell v7은 테스트 연결을 사용할 때 이 문제로 인해 문제가 발생하지 않습니다.
나는 사기를 치고 파워셸 7을 사용할 것입니다.Microsoft는 항상 ping을 실행할 수 없습니다.
test-connection -count 1 yahoo.com,microsoft.com | select destination,status
Destination Status
----------- ------
yahoo.com Success
microsoft.com TimedOut
또는 멀티 스레드:
echo yahoo.com microsoft.com | % -parallel { test-connection -count 1 $_ } |
select destination,status
Destination Status
----------- ------
yahoo.com Success
microsoft.com TimedOut
,'microsoft.com' * 10 | % -parallel { test-connection -count 1 $_ } |
select destination,status
Destination Status
----------- ------
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
microsoft.com TimedOut
# one time takes like 4 seconds
measure-command { ,'microsoft.com' * 10 | % -parallel { test-connection -count 1 $_ } |
select destination,status } | % seconds
9
언급URL : https://stackoverflow.com/questions/41267553/powershell-test-connection-failed-due-to-lack-of-resources
'it-source' 카테고리의 다른 글
노드에 엄격한 모드를 적용할 수 있는 방법이 있습니까? (0) | 2023.09.03 |
---|---|
CSS/HTML: 입력 필드 주위에 빛나는 테두리 만들기 (0) | 2023.09.03 |
파이썬에서 ROC 곡선을 그리는 방법 (0) | 2023.09.03 |
MariaDB 열에서 중첩된 JSON 값을 가져오는 방법은 무엇입니까? (0) | 2023.09.03 |
내 Git 저장소가 왜 그렇게 큰가요? (0) | 2023.09.03 |