powershell - 捕获 RPC 服务器不可用错误 HRESULT : 0x800706BA

标签 powershell powershell-remoting

在 powershell 中,我可以使用 Catch [System.UnauthorizedAccessException] 捕获 Access is Denied 错误。我如何同样捕获 RPC Server Unavailable 错误?

最佳答案

如果您将通用参数 -ErrorAction Stop 添加到 get-wmiobject 命令,在我的例子中,它将导致命令将此非终止错误作为终止错误响应并将其丢弃以捕获操作。

这是我为此目的使用的代码。我可能应该更具体地说明问题,但它现在有效。

# Is this machine on network?, if not, move to next machine
If (!(Test-Connection -ComputerName $computerName -Count 1 -Quiet)) { 
  Write-Host "$computerName not on network."
  Continue # Move to next computer
}

# Does the local Administrator account exist? Returns a string if it exists, which is true-ish.
try {

  $filter = "Name='$olduser' AND Domain='$computerName'"
  $account = Get-WmiObject Win32_UserAccount -Filter $filter -ComputerName $computerName -ErrorAction Stop

} catch {

  Write-Warning "$computerName Can't check for accounts, likely RPC server unavailable"
  Continue # Move to next computer

} #end try

关于powershell - 捕获 RPC 服务器不可用错误 HRESULT : 0x800706BA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8086357/

相关文章:

c# - 无法在 C# 中禁用或启用运行 Powershell 命令的 Exchange 邮箱

powershell - 在生产环境中使用 F# 脚本替换 powershell?

wpf - 如何使用WPF(Powerboots)显示Twitter状态(伪HTML)

powershell - 启动过程和停止分析(-%)参数

来自 invoke-command 的 Powershell 日志记录

powershell - 使用 Invoke-Command 格式化输出

c# - 使用powershell加载C# DLL,[System.Type]::GetType返回null

powershell - PowerShell 控制台输出中的可点击超链接

powershell - 使用 Session 和 CredSSP 的 PSRemoting 错误

powershell - 无需外部工具即可设置新的 Azure 虚拟机