We help IT Professionals succeed at work.
Get Started

VB.NET and exchange 2010 powershell: cannot get all results in collection

Last Modified: 2012-08-21
Dear experts,

I'm programming some maintenance tools in VB.NET interacting with our Exchange 2010 server via PowerShell. Everything works fine but this, here's the simple code snippet:

        Dim command As New Command("Get-Mailbox")
        command.Parameters.Add("Identity", GInitials)

        Dim pipeline = runspace.CreatePipeline()
        Dim results = pipeline.Invoke()

        For Each item In results

Open in new window

Basically, I'm calling the Get-Mailbox cmdlet with the identity switch: "Get-Mailbox -Identity <initials>"
If I run this cmdlet on the exchange server in the Powershell window directly, I get 4 results in columns:

Name / Alias / ServerName / ProhibitSendQuota

Now in my program above, my variable "results" which stores these results, is a
"System.Collections.ObjectModel.Collection(Of System.Management.Automation.PSObject)

So I was expecting to get a collection of the same 4 results..in fact I am not.
When I loop through the collection, I only get 1 result: the 1st one, 'Name'.

How do I get/access the other results??? What I am missing or doing wrong?
I'm actually trying to get the "ServerName"...

Thank you so much for your help.
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE