Vb.net Visual Basic Powershell查询服务器挂起重新启动状态
我是VB.net和Powershell的新手。 我正在编写一个应用程序,查询Win2012服务器的挂起重新启动状态。 我在我的程序中实现了一个很棒的脚本,它正好做到了这一点: 这是我在Zainnab中使用的代码,用于从VB2010.net访问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
'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"))
------
- 我设法使它部分工作
奥肯没有人对这个问题有答案?没有人对这个问题有答案?
Dim ausgabe2 As String
ausgabe2 = RunScript(LoadScript("c:\FHServerStat\PS_PR.stat\60.2.ps1"))
------