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

Formatting default cmdlet output
Last Post 22 May 2008 08:31 PM by DonJ. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
JimMcGillUser is Offline
New Member
New Member
Posts:3

--
24 Apr 2008 04:22 PM  

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
Basic Member
Basic Member
Posts:181

--
28 Apr 2008 01:52 AM  
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...
DonJUser is Offline
PowerShell MVP
Basic Member
Basic Member
Posts:134

--
22 May 2008 08: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.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer