【发布时间】:2019-01-02 12:51:43
【问题描述】:
我编写了一个脚本来从服务器列表中获取 OSVersion。某些服务器不响应“Get-WmiObject”命令。
我想要一个发生此错误的所有主机名的列表。
这为我提供了出现此错误的前几台服务器的列表。
当第一个服务器响应没有错误时,脚本停止。
我希望脚本在服务器未发送错误时不执行任何操作并继续。
有人知道如何解决这个问题。
提前致谢。
我尝试设置“-ErrorAction continue”,但整个脚本没有运行。
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
$arraylist_OSInfo = New-Object System.Collections.ArrayList
$file=Get-Content -Path "C:\Temp\PS-Skripte\server2.txt"
foreach ($Hostname in $file)
{
try
{
Get-WmiObject Win32_OperatingSystem -ComputerName $Hostname -ErrorAction Stop
}
catch [Exception]
{
if ($_.Exception.GetType().Name -eq "COMException")
{
echo "$Hostname - RPC Error" | Out-File -FilePath "C:\temp\PS-Skripte\RPCerror.log" -Append -encoding unicode
}
}
}
我希望从所有发送错误的服务器中获取主机名列表:
"Get-WmiObject : Der RPC-Server ist nicht verfügbar. (Ausnahme von HRESULT: 0x800706BA)"
作为 cmdlet“Get-WmiObject”的答案
【问题讨论】:
标签: powershell exception rpc