如何从PowerShell获取错误& DOTNET

编程入门 行业动态 更新时间:2024-10-26 13:20:15
本文介绍了如何从PowerShell获取错误& DOTNET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

if我无法获得细节错误用于显示给用户。

IfPowerShell Error (User or pwd fail when connect Credential ,Etc..) i cant get detail Error for Show to user.

此我的代码

This My code

公共共享功能执行命令(运行空间为运行空间,命令为字符串)为集合( PSObject)

Public Shared Function ExecuteCommand(runspace As Runspace, command As String) As Collection(Of PSObject)

如果命令为Nothing那么为抛出新的ArgumentOutOfRangeException(" command") 结束如果

If command Is Nothing Then Throw New ArgumentOutOfRangeException("command") End If

如果运行空间为Nothing那么就是抛出新的ArgumentOutOfRangeException(" runspace") 结束如果

If runspace Is Nothing Then Throw New ArgumentOutOfRangeException("runspace") End If

使用ps = System.Management.Automation.PowerShell.Create

Using ps = System.Management.Automation.PowerShell.Create

  ; Dim cmd As New PSCommand cmd.AddScript(命令) ps.Commands = cmd ps.Runspace = runspace

Dim cmd As New PSCommand cmd.AddScript(command) ps.Commands = cmd ps.Runspace = runspace

返回ps.Invoke(Of PSObject)()

Return ps.Invoke(Of PSObject)()

结束使用

End Using

结束功能

推荐答案

使用这段代码和现在checjk。我希望它对您有用。

Hi, Use this code and checjk it now. I hope it will works for you.

尝试runspace.Open()

Try runspace.Open()

将异常作为异常捕获异常如果TypeOf异常是System.Management.Automation。 Remoting.PSRemotingTransportException然后

Catch exception As Exception If TypeOf exception Is System.Management.Automation.Remoting.PSRemotingTransportException Then

选择Case DirectCast(例外, System.Management.Automation.Remoting.PSRemotingTransportException).ErrorCode

Select Case DirectCast(exception, System.Management.Automation.Remoting.PSRemotingTransportException).ErrorCode

案例5

'处理密码问题

退出选择

案例-2144108526

Case -2144108526

'处理网址问题

退出选择

Case Else

Case Else

'流程其他错误

退出选择

结束选择

结束如果结束尝试

End If End Try

更多推荐

如何从PowerShell获取错误& DOTNET

本文发布于:2023-11-26 15:29:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   PowerShell   DOTNET   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!