Author Posts

January 1, 2012 at 12:00 am

by stromnessian at 2013-04-23 13:10:22

Hi

I'm sure there must be a good reason for this, but why, when I try to create a custom object in v3.0 by starting the command:

$obj = [pscust

then try to TAB complete, it completes as [psobject] and when I add a hash table with the desired properties, the resultant object is a hash table? If I want a PSCustomObject, it seems I have to complete the full type name. (Sorry, being picky here, but I don't like typing!!)

Many thanks

by poshoholic at 2013-04-23 21:02:34

That seems like a bug due to how tab completion works in PowerShell and due to the fact that the [pscustomobject] type is actually a special-case [psobject] that PowerShell's interpreter treats differently.

You can see why tab completion is doing what it does by invoking this command:
[pscustomobject].FullName
Compare that to:
[psobject].FullName
That illustrates that [pscustomobject] is actually [psobject]. It provides for a little bit of syntactic magic when it comes to object creation with hash tables.

If it's a bug that you really want to see fixed, you should open a bug report on Microsoft Connect and encourage others to vote it up.

by stromnessian at 2013-04-24 00:23:12

Thanks, Kirk.