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.
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.
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.
PSTypeName = 'MyObject'}
Name Address City State Zip
---- ------- ---- ----- ---
me here la ca 11111