header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Subject: Formatting default cmdlet output
Prev Next
You are not authorized to post a reply.

Author Messages
JimMcGillUser is Offline
New Member
New Member
Posts:3

04/24/2008 8:22 AM  

I've written a custom cmdlet that chews through a binary file and creates well behaved PSObjects that "where" and cmdlets like "FT" operate on correctly. But the default output, if I don't pipe my output into something else, is FL dumping all the data. Does the job but isn't succinct. I’d like to define a default custom output format. I see some evidence that this is an XML file, but I haven’t been able to find any description of how to hook it up in the current version of PowerShell  (there is some discussion about doing that with Monad, but that doesn’t seem to work anymore). Anybody know of a full example out there on the web that discusses how you hook the XML up, where you put it, and what xml keys are expected?

marco.shawUser is Offline
Co-Community Director
Power User
Power User
Posts:151

04/27/2008 5:52 PM  
http://msdn2.microsoft.com/en-us/library/ms714665(VS.85).aspx

Basically you create your custom .ps1xml file, then use the update-typedata cmdlet to apply the formatting.

Let me know if you need a complete example...

Marco

*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp
*PowerGadgets MVP: http://www.powergadgets.com/mvp
*Blog: http://marcoshaw.blogspot.com
DonJUser is Offline
PowerShell MVP
Moderator
Moderator
Posts:642

05/22/2008 12:31 PM  
Although you can't really do default formatting for a PSObject. Your cmdlet needs to define a new class and output objects of that class. This is all because the formatting subsystem relies on the object's type name to apply formatting; if you're using a generic PSObject it can't be differentiated from all the other things that output PSObject. If you use a custom type, the formatting system can distinguish it.

"Windows PowerShell: TFM, 2nd Edition" has a detailed chapter on the formatting XML files, how to load them into the shell, etc.

- Don Jones
www.ConcentratedTech.com
Subscribe (RSS) or visit for weekly PowerShell tips and lessons
You are not authorized to post a reply.
Forums > PowerShell Development > Cmdlet Development > Formatting default cmdlet output



ActiveForums 3.7
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer