【发布时间】:2023-03-25 13:14:01
【问题描述】:
您好,我正在开发一些 VB.net 应用程序来管理我的 Exchange 2010 服务器上的分发列表。此代码调用具有 2 个参数的 ps1 脚本及其工作。我唯一的问题是我想捕获 PowerShell.Invoke() 的输出。执行后 PowerShellCommandResults 总是为空 集合中没有记录。
也许问题来自于从 ps1 文件中捕获,但我真的不知道在哪里可以解决我的问题
谢谢
Dim PowerShell As Management.Automation.PowerShell = PowerShell.Create()
Dim PowerShellCommand As New PSCommand()
Dim PowerShellCommandResults As Collection(Of PSObject)
PowerShellCommand.AddCommand("c:\scripts\connect.ps1")
PowerShellCommand.AddCommand("c:\scripts\newld.ps1")
PowerShellCommand.AddArgument("test@cscapitale.qc.ca")
PowerShellCommand.AddArgument("Distribution liste test")
Try
PowerShellCommandResults = PowerShell.Invoke()
Dim sw As New StreamWriter("C:\" & Now.ToLongDateString & ".txt")
For Each line In PowerShellCommandResults
sw.WriteLine(line.ToString)
Next
sw.Dispose()
PowerShell.Dispose()
Catch ex As Exception
End Try
【问题讨论】:
标签: powershell output vb.net-2010