Is it possible to format a PSObject with a .ps1xml file?

This might be a totally ridiculous question...but here goes anyway:

I have a couple of filters in modules that write PSObjects to output 
using code like:

$x = New-Object PSObject -Property @{
   one = "one"
   two = "two"
}
Write-Output $x

There's just way more properties.  How does one specify 'default' 
formatting styles for a System.Management.Automation.PSCustomObject like 
you can with other types using .ps1xml files?  That may not even be the 
right question to ask.  What I'd like would be a way to define the 
default formatting for format-table, format-list, etc for the output of 
filters/functions that don't output standard .NET types.

~Clint
0
Clint
2/23/2010 4:17:00 AM
windows.powershell 690 articles. 0 followers. Follow

3 Replies
2050 Views

Similar Articles

[PageSpeed] 29

i found a sample`

<?xml version="1.0" encoding="utf-8" ?>

<Types>

     <Type>
	<Name>System.Xml.XmlElement</Name>
	<Members>
	    <ScriptMethod>
		<Name>toString</Name>
		    <Script>$this.path</Script>
	    </ScriptMethod>
                       <MemberSet>
		<Name>PsStandardMembers</Name>
		<Members>
			<PropertySet>
				<Name>DefaultDisplayPropertySet</Name>
				<ReferencedProperties>
			  	   <Name>Artist</Name>
			  	   <Name>Album</Name>
			  	   <Name>Title</Name>
			  	   <Name>Track</Name>
				</ReferencedProperties>
	   		</PropertySet>
		</Members>
	   </MemberSet>
	</Members>
     </Type>
</Types>


On 02-23-2010 12:17 PM, Clint Bergman wrote:
> This might be a totally ridiculous question...but here goes anyway:
>
> I have a couple of filters in modules that write PSObjects to output
> using code like:
>
> $x = New-Object PSObject -Property @{
> one = "one"
> two = "two"
> }
> Write-Output $x
>
> There's just way more properties. How does one specify 'default'
> formatting styles for a System.Management.Automation.PSCustomObject like
> you can with other types using .ps1xml files? That may not even be the
> right question to ask. What I'd like would be a way to define the
> default formatting for format-table, format-list, etc for the output of
> filters/functions that don't output standard .NET types.
>
> ~Clint

0
ryan
2/23/2010 9:13:05 AM
Thanks, Ryan, that seems like a step in the right direction.  I saved 
the file as Types.ps1xml in the module directory and set the contents to:

<?xml version="1.0" encoding="UTF-8"?>
<Types>
   <Type>
     <Name>System.Management.Automation.PSCustomObject</Name>
     <Members>
       <MemberSet>
         <Name>PsStandardMembers</Name>
         <Members>
           <PropertySet>
             <Name>DefaultDisplayPropertySet</Name>
             <ReferencedProperties>
               <Name>GPOName</Name>
               <Name>extensionGPOSection</Name>
               <Name>extensionName</Name>
             </ReferencedProperties>
           </PropertySet>
         </Members>
       </MemberSet>
     </Members>
   </Type>
</Types>

and then ran:
Update-TypeData -PrependPath \\<PathToModule>\Types.ps1xml

And when I used the first filter which writes a CustomPSObject to the 
pipeline got the default output I was looking for.  However, as a side 
effect:

PS # New-Object psobject -property @{ one = "one" }

GPOName  extensionGPOSection  extensionName
-------  -------------------  -------------

Those property sets are now the default for every CustomPSObject written 
to output, which is of course how it's supposed to work.  Trouble is for 
my module I don't have the same propety sets for every CustomPSObject 
written to output by the functions.  Is there a way to customize this 
display without defining new types?  If not, must one build these new 
types in .NET and import them into the PSSession using Add-Type?  Or can 
they be built on the fly in PowerShell or defined in a script module or 
module manifest somehow?

-- 
v(^_^)~Clint
http://outputredirection.blogspot.com
0
Clint
2/23/2010 6:34:36 PM
Bam, got it.

Combine the below technique:
http://poshoholic.com/2008/07/03/essential-powershell-name-your-custom-object-types/

With the Types.ps1xml and Update-TypeData like Ryan suggested and we 
have an answer!
Thanks, everyone!
-- 
v(^_^)~Clint
http://outputredirection.blogspot.com
0
Clint
2/23/2010 6:53:08 PM
Reply:

Similar Artilces:

File formats
I have a question concerning file formats. As a small business manager using personal computers in the workplace is essential. Over the course of any fiscal year documents are generated and files produced which are important for maintaining from year to year. Often these important files are generated in Microsoft Word and Excel in my work. I recently referred to one such file that was 5 years old to see the frightening words: “File Error: data may have been lost.” My question related to which file formats are best for file retention. I am not interested in paying a com...

Copy Paste Conditional Formatting
I have used conditional formatting to identify certian parameters. I must now copy that column to another spreadsheet but do not want to lose that highlighted data. I have tried Copy Paste Special but I can only copy the Values. Is there any way to copy those cells and the colors? If you do a copy/paste special/formats, you'll get the conditional formats (and other formats) into the destination cells, without changing the values already in those cells. -- Jim "Bud Hughes" <BudHughes@discussions.microsoft.com> wrote in message news:CAA3085A-642D-4645-ADC5-24FF967...

Conditional formatting on book shared
Hi, I know when a book is shared, conditional formatting is unavailable but is there any way to get (or see) the conditions of this cell ? thanks in advance loparqu -- Message posted from http://www.ExcelForum.com Can you copy the cell and paste into a new workbook's worksheet and look at the CF there? "loparque <" wrote: > > Hi, > I know when a book is shared, conditional formatting is unavailable, > but is there any way to get (or see) the conditions of this cell ? > > thanks in advance > > loparque > > --- > Message posted from ...

Files opening with different file names
Good afternoon/morning. Having a strange issue with Excel at present. If a file is sitting on my desktop, called invoices.xls, I click on it to open, and it opens as invoices1 The same happens if I 'explore' to the file. However, if I open excel and then click 'file''open' then click on the file, it opens as invoices.xls. When trying to save invoices1 it will save as invoices1.xls, then if I open this it will open it as invoices11 I'm running Windows 2000 with Excel 2000. Any help/guesswork would be appreciated! It sounds like the default behavior when you ...

Is it possible
I would like to know is it possible to make million dollar in the internet, if you have any suggestions, write on my forumhttp://isitpossible.truemillion.comMark...

Format so first column always appears
I have a wide worksheet and want the first column to always appear as I scroll to the other columns. I would look it up but I can't figure out where to look and under what title. Thanks It's referred to as Freeze Panes. Position your cursor in B1 then click on View | Freeze Panes | Freeze Panes (Excel 2007 or later), or Window | Freeze Panes (Excel 2003 or earlier). Hope this helps. Pete On Aug 20, 1:26=A0am, Gianni <gia...@gianni.com> wrote: > I have a wide worksheet and want > the first column to always appear > as I scroll to the other columns. > > I would...

Personal Folders in OWA
Hello, I have just enabled OWA on our Exchange 2003 SP2 through ISA Server 2004. Is there any way to access personal folders in OWA? Thanks in advance. If by personal folders you mean .pst files, the answer is NO! Sorry. C C wrote: > Hello, > > I have just enabled OWA on our Exchange 2003 SP2 > through ISA Server 2004. Is there any way to > access personal folders in OWA? > > Thanks in advance. > > "C C" <someone@atsbcglobal.net> wrote: >I have just enabled OWA on our Exchange 2003 SP2 >through ISA Server 2004. Is there any way...

Date Format for Userform TextBox
Hi I run Excel 2K I have a userform that uses a textbox fot entering a date: When I enter a date in my spreadsheet I type (for example) 2/3 an this returns 2/Mar/2009 However when I type 2/3 in the textbox in the userform it returs 3/Feb/2009 So, the textbox interprets the 2 as the month and the 3 as the date. This is unlike entering it directly into the spreadsheet which interprets the 2 and the date and 3 as the month. I would like the textbox to operate like the spreadsheet where it interprets the 2 as the date and the 3 as the month. This is the code I am presently using:- Pri...

Custom Number Format #6
I created a custom number format #,##0,_);(#,##0,) that rounds number to thousands but it also shows 0 as blank. I need a format that als shows "0" as "0". Thanks for your help -- Message posted from http://www.ExcelForum.com Hi try #,##0,_);(#,##0,);0 >-----Original Message----- >I created a custom number format #,##0,_);(#,##0,) that rounds numbers >to thousands but it also shows 0 as blank. I need a format that also >shows "0" as "0". > >Thanks for your help. > > >--- >Message posted from http://www.ExcelForum.com/...

ON 07: Huge File Size
I have a section in ON 07 with about 7 pages. Most have very little on them. There are 2 or 3 screen clips and several items that were pasted. When I check Windows Explorer it shows the section is 52MB (MEGA, not kilo)! This seemed impossible to me, so I saved it as a pdf file. As a pdf file, it is 804KB (KILO)! This seems like the right size. I have WinXP (sp3)-- if it matters. What is happening here? David What size are the pasted files? And how large (would you estimate) the screen clippings are? -- Thanks, John Guin OneNote Test Team http://...

Help
Greetings All, I'm having a problem creating the type of bar chart for a time line This 'LINK (http://www.mississippi.net/~comcents/tendertale.com/tttl/tttl.html will give you several examples of what I'm talking about. If anyone can help me, I would really appreciate it. I'm currently using Excel 2000. Thanks, Bo -- w5bl ----------------------------------------------------------------------- w5blt's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1620 View this thread: http://www.excelforum.com/showthread.php?threadid=27625 Hi, The type of...

Attachments sent as .dat file.
When I attach a document or Excel spreadsheet, they end up as winmail.dat in the recipient's e-mail. I hope the answer is out there somewhere and would appreciate assistance. Regards, Alan Don't send the mail item in Richt Text Format. Use Plain Text or HTML instead "Alan Ak" <anonymous@discussions.microsoft.com> wrote in message news:047401c3adba$5078eb50$a601280a@phx.gbl... > When I attach a document or Excel spreadsheet, they end up > as winmail.dat in the recipient's e-mail. I hope the > answer is out there somewhere and would appreciate > assi...

linking Excel 2007 worksheet to Word 007 file
Does anyone know why a border would show up around the excel worksheet linked to Word? I've checked the settings in excel to see that there are no borders. Also, when I initially link the excel file, everything looks fine but if I refresh it once or twice, a border (ie box) shows up around the linked worksheet. On 31/05/2010 1:20 PM, bmb wrote: > Does anyone know why a border would show up around the excel worksheet linked > to Word? I've checked the settings in excel to see that there are no > borders. Also, when I initially link the excel file, everything lo...

Disable Recieving of files
I want to setup a mailbox on my server so that a user can send emails to their home email account, but not be able to recieve. Is this possible? Michael, Could you rephrase the question? I am not sure what you are trying to do. You can setup a contact that will forward e-mails sent to the server to another address. -- Jared Gradle Exchange Support Professional ****** Disclaimer ****** This posting is provided "AS IS" with no warranties, and confers no rights. Note: Please do NOT reply to this e-mail address. It is used for newsgroup purposes only. "Michael San Filippo...

Downloading Statements Directly Not Possible
I have Money 2002 installed on an Win XP Pro SP1 machine. Something happened and I probably did it, that causes the statement downloads not to go directly to the account. Rather they want to be saved in a file and then opened into Money. I then have to delete the download. I have tried several things in order to fix this: 1. I verified the file associations of OFC, OFX were correct. They were. 2. Lowered all my security settings in IE. Even put banks into Trusted site zone. No go. 3. Made new accounts. Didn't help. 4. My IE cache is large (500MB) and regularly cleaned out. 5. I made s...

is this possible? reload a form that is based on a query with new query that is defined in the form.
I have a basic form. The form is based on a query, so when I open the form, a pop comes up where I enter in what I want to query. So instead of 30,0000 records, I get 1-10 records. on the form, I have a text box. I want to be able to enter in what I want to query next and afterupdate have the recordset/form reload with that query instead of my original qeury. I figure this has to be done with VB. I am just starting to learn some VB but I am lost. Any info would be great, thank you. It does. You need to apply the new query or table name, or the sql string to the forms recordsource, then...

.eml file extension
When trying to open an attachment that has a *.eml extension I get the following pop-up error message. "Paint cannot read this file. This file is not a valid bitmap file, or its format is not currently supported." Any suggestions? Regards Rightclick the file, choose Open With... and select Outlook Express. Mark it to set it as the default application for eml-files. Note that this is an Microsoft Office Outlook forum. Outlook Express is family of Internet Explorer and Outlook of the Office family. Here is the link for the right forum http://communities.microsoft.com/newsg...

How do I copy a Word File to an email that has numbered lists in
When I send an email and copy a Word Document that has a numbered list in the body such as 1. 2. 3. etc. the numbers for each line disappear in the email message. How can I prevent this? Email messages generally don't preserve formatting. Send the Word doc as an attachment, or (probably better) convert it to pdf and send that. On Feb 23, 4:05=A0pm, Edward P <Edward P...@discussions.microsoft.com> wrote: > When I send an email and copy a Word Document that has a numbered list in= the > body such as 1. =A0 2. =A0 3. =A0etc. the numbers for each line disappea...

Conditional Formatting
All: I have a sheet with conditional formatting applied, the conditions work but once I save and come back, when the specific conditional format is triggered, it looks like nothing happened. When you scroll up/down or switch between tabs and then come back, that's when the conditional formatting is visible. Working in Excel 2007 and it's important for users to see the formatting happening in view, and not having to scroll back and forth to see the changes. Any thoughts why this is happening? Thank you. ...

which file include " IOleCommandTarget"?
hi guys, I want to implement IOleCommandtarget interface using VC6 ATL, but can't find which Typelibray to use for this interface. Thanks in advance! ...

Address format
Is it possible to save email addresses in the format? "Firstname Surname" securemail@domain.com This is required for a gateway certificate server. Microsoft <peter@4dt.co.za> wrote: > Is it possible to save email addresses in the format? > > "Firstname Surname" securemail@domain.com > > This is required for a gateway certificate server. Save them where? -- Brian Tillman [MVP-Outlook] ...

Search file and within the file
Hi, I have several files in a folder most of them are CVs in word format, I want to create a query or access program to get the subject with some criteria - any ideas? If I search for a particular Text, that should check and matching file name and also inside the word file. I tried google desktop search, coppernic search and even the MS Search - but nothing helped in a way I want. I appreciate your valuable time. Rgds Anver, To develop a bespoke Access application will take much effort and involve using Windows APIs. I suggest you don't want to do this. Instead consider upgrad...

I need an excel plug in to save workbooks in adobe acrobat format
I used to have this feature on the toolbar, but following a severe recent excel and outlook crash, it got wiped off !! There seems to be no way to restore this essential facility, of choosing to save excel workbooks in a pdf format instead of xls. DOes anyone know how to restore it? Hi Chris, Try-File, Print, then select Acrobat Distiller. It will then ask you where you want the .pdf file to be saved. Thats how it works on mine. Hope that helps "chris brown" wrote: > I used to have this feature on the toolbar, but following a severe recent > excel and outlook crash,...

Possible to detect changes to an XmlDocument object?
If I instantiate an XmlDocument object, the load a file through the Load method, is there a way, later on in execution, to easily determine if the XmlDocument object has changed from the original version loaded? I'd like to be able to check a condition to see if the document in memory has been editted (i.e., nodes added, attributes changed, etc.) so that my user can decide whether or not to commit changes to the disk file before moving to another file. Will I have to resort to re-loading the file, and comparing OuterXml properties? Gabe Gabe Covert wrote: > I'd like t...

Error msg "The system cannot find the file specified"
Hello all, I'm using MS Outlook 2000. I have received an above alert from Outlook when I tried to open the attachment (excel file only)in mail folders. For other file types(such as .doc, .jpg, .tif...) I can open easily. Would be much appreciated if you can help me to solve the problem. Thanks and best regards Tuan ...