It seems that OutVariable is broken when using the Exchange 2010 cmdlets. Is it just my server or is this the case for everyone? I observed the following --
get-mailbox jdoe -OutVariable asdf | out-null
$asdf.getType()
You cannot call a method on a null-valued expression.
At line:1 char:14
+ $asdf.getType <<<< ()
+ CategoryInfo : InvalidOperation: (getType:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
In the example above, $asdf
is never created and get-mailbox jdoe
absolutely returns something.
get-childitem -OutVariable asdf | out-null
$asdf.getType()
[PS] C:\temp>$asdf.getType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
In this example, $asdf
is created as expected since get-childitem
is not an Exchange 2010 cmdlet.
-OutVariable
as a common parameter is implemented by the PowerShell runtime – not the cmdlet – therefore this is not about Exchange cmdlets.$asdf = get-mailbox jdoe -OutVariable
?$asdf = get-mailbox jdoe -OutVariable
is just incorrect syntax and rejected as such. The manner in which I used them is correct in both examples above. It simply doesn't work properly in the first. Is anyone else able to reproduce this behavior?