Powershell w/ Exchange in vb.net – Work in Progress

I used this code to connect up to Exchange through Powershell with vb.net.

However this is not the release code used in my projects as thats went missing…. – so I’m sticking this here with a view to update if / when I find my code.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim rsConfig As RunspaceConfiguration
        rsConfig = RunspaceConfiguration.Create()
        Dim snapInException As PSSnapInException = Nothing
        Dim info As PSSnapInInfo
        info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", snapInException)
        Dim myRunSpace As Runspace
        myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)
        myRunSpace.Open()
        Dim pipeLine As Pipeline
        pipeLine = myRunSpace.CreatePipeline()
        Dim myCommand As New Command("Get-Command")
        pipeLine.Commands.Add(myCommand)
        Dim commandResults As System.Collections.ObjectModel.Collection(Of PSObject)
        commandResults = pipeLine.Invoke()
        For Each cmdlet As PSObject In commandResults
            Dim cmdletName As String
            cmdletName = cmdlet.Properties("Name").Value.ToString()

        Next

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.