Hi I'm working on a little VB.net apps to manage my distribution list on my exchange 2010 server. This code call a ps1 scripts with 2 arguments and its work. the only problem I have is I want to trap the output of the PowerShell.Invoke(). after the execution PowerShellCommandResults is allways empty no records in the collection.
Maybe the problem come from trapping from ps1 file but I really don't know where to look at to resolve my problem
thx
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("[email protected]")
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