Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Exchange commands in VB (PLEASE HELP!)

$
0
0

Hey everyone, I'm running exchange PowerShell commands from my VB program and I have a quick question. Would it be possible to input my server name where I want to pull the information off of right after it says Get-MailBoxDatabaseCopyStatus. For an example:

RemotePowerShell.AddCommand("Get-MailboxDatabaseCopyStatus -Servername"

^this command works in Exchange(obviously after I input the real server name" but when I try to run it in VB, I get an error saying it doesn't recognize this command.

Here is my code:

Public Class frmEmailValidation

    Dim username As String = "server\username"

    Dim password =  "password"

    Dim Count As Integer


    Function GetUsersUsingBasicAuth( _

    ByVal LiveIDConnectionUri  As String, ByVal ScehmaUri As String, _

    ByVal Credentials  As PSCredential,  ByVal Count As Integer) As Collection(Of PSObject)


        Dim ConnectionInfo  As WSManConnectionInfo = _

            New WSManConnectionInfo(New Uri(LiveIDConnectionUri), ScehmaUri, Credentials)

        ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic


        ScehmaUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"


        LiveIDConnectionUri = "http://exchangeserver/Powershell?serializationLevel=Full"


        Credentials = New  PSCredential(username, password)


      

        Dim RemoteRunspace  As Runspace

        RemoteRunspace = RunspaceFactory.CreateRunspace(ConnectionInfo)


        Return GetUserInformation(Count, RemoteRunspace)


        Count = 5


    End Function


    Function GetUserInformation(ByVal Count As Integer,  ByVal RemoteRunspace As  Runspace) As Collection(Of PSObject)


        Dim RemotePowerShell  As PowerShell =  PowerShell.Create

        RemotePowerShell.AddCommand("Get-MailboxDatabaseCopyStatus")

        


        ' Open the remote runspace on the server.

        RemoteRunspace.Open()


        ' Associate the runspace with the Exchange Management Shell.

        RemotePowerShell.Runspace = RemoteRunspace


        ' Invoke the Exchange Management Shell to run the command.

        Return RemotePowerShell.Invoke



    End Function


Viewing all articles
Browse latest Browse all 7132

Trending Articles