Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Visual Basic Powershell查询服务器挂起重新启动状态_Vb.net_Powershell_Status_Reboot - Fatal编程技术网

Vb.net Visual Basic Powershell查询服务器挂起重新启动状态

Vb.net Visual Basic Powershell查询服务器挂起重新启动状态,vb.net,powershell,status,reboot,Vb.net,Powershell,Status,Reboot,我是VB.net和Powershell的新手。 我正在编写一个应用程序,查询Win2012服务器的挂起重新启动状态。 我在我的程序中实现了一个很棒的脚本,它正好做到了这一点: 这是我在Zainnab中使用的代码,用于从VB2010.net访问Powershell并以字符串形式返回结果 'Takes script text as input and runs it, then converts 'the results to a string to return to the user

我是VB.net和Powershell的新手。 我正在编写一个应用程序,查询Win2012服务器的挂起重新启动状态。 我在我的程序中实现了一个很棒的脚本,它正好做到了这一点:

这是我在Zainnab中使用的代码,用于从VB2010.net访问Powershell并以字符串形式返回结果

'Takes script text as input and runs it, then converts
    'the results to a string to return to the user
    Private Function RunScript(ByVal scriptText As String) As String
    'create Powershell runspace
    Dim MyRunSpace As Runspace = RunspaceFactory.CreateRunspace()

    'open it
    MyRunSpace.Open()

    ‘ create a pipeline and feed it the script text
    Dim MyPipeline As Pipeline = MyRunSpace.CreatePipeline()

    MyPipeline.Commands.AddScript(scriptText)

    ‘ add an extra command to transform the script output objects into nicely formatted strings
    ‘ remove this line to get the actual objects that the script returns. For example, the script
    ‘ "Get-Process" returns a collection of System.Diagnostics.Process instances.
    MyPipeline.Commands.Add("Out-String")

    ‘ execute the script
    Dim results As Collection(Of PSObject) = MyPipeline.Invoke()

    ‘ close the runspace
    MyRunSpace.Close()

    ‘ convert the script result into a single string
    Dim MyStringBuilder As New StringBuilder()

    For Each obj As PSObject In results
        MyStringBuilder.AppendLine(obj.ToString())
    Next

    ‘ return the results of the script that has
    ‘ now been converted to text
    Return MyStringBuilder.ToString()

End Function
#

Dim ausgabe2 As String
            ausgabe2 = RunScript(LoadScript("c:\FHServerStat\PS_PR.stat\60.2.ps1"))
------
  • 我设法使它部分工作
我遇到的问题是,通过在powershell中执行脚本,结果是正确的

通过visual basic执行脚本,返回的某些值不正确,但请参见:

请帮我解决这个问题

问候


奥肯

没有人对这个问题有答案?没有人对这个问题有答案?
Dim ausgabe2 As String
            ausgabe2 = RunScript(LoadScript("c:\FHServerStat\PS_PR.stat\60.2.ps1"))
------