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

PSObject formatting (types.ps1xml and format.ps1xml) directly from code
Last Post 26 Aug 2008 03:03 AM by halr9000. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
TeX HeXUser is Offline
New Member
New Member
Posts:1

--
25 Aug 2008 07:18 PM  

I just wanted to share that I have created a small class that can create the XML needed for types.ps1xml and format.ps1xml directly from the code of your custom object by using attributes.

For example:

        [xPSProperty(Default = true, Alias = "FullName") 

      public string Name

Will result in an XML like this (sorry, the forum does not allow direct XML input so I can only show the paths inside the XML)

      DefaultDisplayProperty/FullName     

      DefaultDisplayPropertySet/FullName

You can also generate the XML for the table view

        [xPSProperty(Default = true, Sequence = 1, Alias = "FullName", ColumnWidth = 30)]
        public string Name

 

      [xPSProperty(Sequence = 2, ColumnName = "Size (K)", ColumnRightAligned = true, ColumnScript = "[int]($_.Size / 1024)")]

        public int Size

 

More examples, a detailed description and the source code is available at this address:

http://texhex.blogspot.com/2008/08/automatically-generating-powershell.html

 

halr9000User is Offline
Basic Member
Basic Member
Posts:303

--
26 Aug 2008 03:03 AM  
This is awesome work man!
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