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

How to: Get a list of mail users by using the Exchange Management Shell

$
0
0

Hello every one, quick question: When I run this code below for VB, how will I see the results of the program? Is there anyway I can make the results appear in a message box?

Function GetUsersUsingBasicAuth( _
    ByVal LiveIDConnectionUri AsString, ByVal ScehmaUriAsString, _
    ByVal Credentials As PSCredential, ByVal CountAsInteger)As Collection(Of PSObject)

    Dim ConnectionInfo As WSManConnectionInfo = _
        New WSManConnectionInfo(New Uri(LiveIDConnectionUri), ScehmaUri, Credentials)
    ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic

    Dim RemoteRunspace As Runspace
    RemoteRunspace = RunspaceFactory.CreateRunspace(ConnectionInfo)

    Return GetUserInformation(Count, RemoteRunspace)

  EndFunction

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

    Dim RemotePowerShell As PowerShell = PowerShell.Create
    RemotePowerShell.AddCommand("Get-Users")
    RemotePowerShell.AddParameter("ResultSize",Count)

    ' 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

EndFunction


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>