3

I'm trying to run Exchange 2010 cmdlets such as this one:

Get-Mailbox UserName -ErrorVariable err

However, the cmdlets seem to completely ignore the -ErrorVariable parameter: the variable $err is never created or modified, regardless of the command's success or failure.

Why is this happening, and how can I make them work like they should (i.e. populating the variable with the actual command result)?

This works perfectly on Exchange 2007, or with any other cmdlet which isn't specific to Exchange 2010.

Massimo
  • 68,714
  • 56
  • 196
  • 319

1 Answers1

3

After googling for a while and finding lots of people sharing the same problem, I opened a support call with Microsoft. They told me to use globally-scoped variables instead of standard ones, and everything started working as expected:

Get-Mailbox UserName -ErrorVariable global:err

This is, of course, mentioned absolutely nowhere in the product documentation (as of today; I sincerely hope they are going to update it after my support call).


The same behaviour also applies to -OutVariable: OutVariable is broken for Exchange 2010 cmdlets.

Massimo
  • 68,714
  • 56
  • 196
  • 319