小编csc*_*ker的帖子

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
Run Code Online (Sandbox Code Playgroud)

因此,当您需要在循环中测试计算机列表时,它不可靠且相当无用.是否有可靠的修复,替代或解决方法来实现此功能?

这是我目前的解决方案,但它仍然不够可靠(有时它们仍然连续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 …
Run Code Online (Sandbox Code Playgroud)

powershell ping

18
推荐指数
3
解决办法
2万
查看次数

标签 统计

ping ×1

powershell ×1