I'm running the following inside my visual studio project and I'm looking to obtain two things:
1) I have to import a pssession to utilize some exchange cmdlets. I do this with $session = path to server, etc... and then
import-pssession $session -allowclobber -disablenamechecking -verbose:$false |out-null
But yet, in my capture of verbose output, it's continually displaying the typical verbose output for this:
VERBOSE: Importing function 'Get-...', etc, etc...
How can I supress these messages?
2) The other component of this is that when my powershell script completes, I'm using
I'd like to grab that exit code, but it doesn't seem that my current code picks it up.
Here's the relevant snippet:
Dim outputCollection As New PSDataCollection(Of PSObject)()
'outputCollection.DataAdded += outputCollection_DataAdded <<< Not sure if this is part of my problem. It was in the source, but I couldn't get it working in vb.net (converted from c#)
' the streams (Error, Debug, Progress, etc) are available on the PowerShell instance.
' we can review them during or after execution.
' we can also be notified when a new item is written to the stream (like this):
'PowerShellInstance.Streams.[Error].DataAdded += Error_DataAdded
'changed above to:
AddHandler PowerShellInstance.Streams.Error.DataAdded, AddressOf Error_DataAdded
AddHandler PowerShellInstance.Streams.Verbose.DataAdded, AddressOf Verbose_DataAdded
Dim result As IAsyncResult = PowerShellInstance.BeginInvoke(Of PSObject, PSObject)(Nothing, outputCollection)
Console.Write(vbTab & "Waiting for pipeline to finish")
While result.IsCompleted = False
Console.Write("Execution is: )
Catch ex As Exception
Console.WriteLine("Execution failed. Exception is " & ex.Message)
Output that I don't want looks like this: ('Waiting for pipeline to finish', is expected)
Waiting for pipeline to finishVERBOSE: Loading module from path 'C:\Users\xxxxxx
VERBOSE: Importing function 'Add-ADPermission'.
VERBOSE: Importing function 'Add-AvailabilityAddressSpace'.
VERBOSE: Importing function 'Add-ContentFilterPhrase'.
VERBOSE: Importing function 'Add-DatabaseAvailabilityGroupServer'.
VERBOSE: Importing function 'Add-DistributionGroupMember'.
VERBOSE: Importing function 'Add-FederatedDomain'.
VERBOSE: Importing function 'Add-IPAllowListEntry'.
VERBOSE: Importing function 'Add-IPAllowListProvider'.
VERBOSE: Importing function 'Add-IPBlockListEntry'.