Output 5 properties as a table?

Is there some variable I can set to 5 instead of 4, so that 5 properties in a script will output as a table instead of a list by default?

PS /Users/js> [pscustomobject]@{name='me';address='here';city='la';state='ca';zip=11111
  PSTypeName = 'MyObject'}   



name    : me
address : here
city    : la
state   : ca
zip     : 11111




Nope. Use format-table.

How does get-process do it? Can I have a script output a new object, and then use a simple here-string or file with update-formatdata that makes it use format-table by default? I guess [OutputType(‘MyObject’)] doesn’t work in scripts.

EDIT:
Ok, I have “PSTypeName = ‘MyObject’”

Get-Process has a predefined view in a .format.ps1xml file; that mandates that the output object have a unique type name (which you can apply). Covered extensively in “PowerShell In Depth” if you’re interested ;). But yes, you apply a custom type name to the object, and then import a .format.ps1xml file.

How does the format file pick whether the default view is table or list?

The format file defines a view, which I s either a table view or a list view. If it defines more than one, then the first one is the one it uses unless you use the -Name parameter of a Format- command to specify a different view. Process objects, for example, have two defined table views and the first one is the one you normally see.

Ok, here it is. It would be nice if I could use a here-string.

update-formatdata myobject.format.ps1xml
[pscustomobject]@{name='me';address='here';city='la';state='ca';zip=11111
  PSTypeName = 'MyObject'}

Name             Address          City             State            Zip
----             -------          ----             -----            ---
me               here             la               ca               11111