Windows Vista Forums

Type formatting question on properties that are collections
  1. #1


    Keith Hill [MVP] Guest

    Type formatting question on properties that are collections

    OK I'm trying to figure out it is that some collections get expanded and some don't. I have a Send-SmtpMail cmdlet that spits out the MailMessage object and that it sends and the output needs a little work:

    5> gps w* | Send-SmtpMail -to john@doe.com,jane@doe.com -Subject "Test" -Body "Hi" -AttachmentPath \temp\foo.* -whatif
    What if: Performing operation "Send-SmtpMail" on Target "System.Net.Mail.MailMessage".


    From : rkeithhill@dev.null.com
    ReplyTo :
    To : {, }
    CC : {}
    Bcc : {}
    Attachments : {foo.bar, foo.bat, foo.bli, foo.config, foo.cs, foo.dll, foo.ksh, foo.msh, foo.ps1, foo.reg, foo.sln, foo
    .txt, foo.xml}
    Priority : Normal
    Subject : Test
    IsBodyHtml : False
    Body : Hi
    Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
    ------- ------ ----- ----- ----- ------ -- -----------
    756 209 5788 2128 137 20.00 668 wcescomm
    139 5 3420 1484 45 5.06 4372 WCESMgr
    225 6 1720 6268 51 24.06 204 WeatherDataClient
    237 6 6712 2336 78 46.30 3124 WindowsSearch
    690 69 13560 3376 78 89.30 1756 winlogon
    672 16 14560 23764 107 58.27 2512 winss
    192 6 6712 2020 54 31.11 1640 winssnotify
    148 3 1884 5076 37 13.86 1100 wmiprvse
    505 21 82364 79656 177 44.75 7884 wmplayer

    Now why does the Attachments collection (AttachmentsCollection) contents get displayed but the To collection (MailAddressCollection) contents don't get displayed?



    --
    Keith

      My System SpecsSystem Spec

  2. #2


    Jeffrey Snover [MSFT] Guest

    Re: Type formatting question on properties that are collections

    Do the following:
    5> $x = gps w* | Send-SmtpMail -to john@doe.com,jane@doe.com -Subject "Test" -Body "Hi" -AttachmentPath \temp\foo.* -whatif
    What if: Performing operation "Send-SmtpMail" on Target "System.Net.Mail.MailMessage".
    6> $x.To |Format-list *
    7> $x | %{"$_"}

    And send the results.
    --
    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.



      My System SpecsSystem Spec

  3. #3


    Keith Hill [MVP] Guest

    Re: Type formatting question on properties that are collections

    Here ya go:

    2> $x.To | Format-List *


    DisplayName :
    User : john
    Host : doe.com
    Address : john@doe.com

    DisplayName :
    User : jane
    Host : doe.com
    Address : jane@doe.com



    3> $x | %{"$_"}
    System.Net.Mail.MailMessage
    4> $x


    From : rkeithhill@comcast.net
    ReplyTo :
    To : {, }
    CC : {}
    Bcc : {}
    Attachments : {foo.bar, foo.bat, foo.bli, foo.config, foo.cs, foo.dll,
    .txt, foo.xml}
    Priority : Normal
    Subject : Test
    IsBodyHtml : False
    Body : Hi

    Hmm, perhaps the MailAddress object is using the DipslayName as its representation? How do I override that behavior for the display of a collection of those objects?

    --
    Keith
    "Jeffrey Snover [MSFT]" <jsnover@ntdev.microsoft.com> wrote in message news:BCCFD5C4-8FDC-4F4E-A5D2-2B9113B07BA4@microsoft.com...
    Do the following:
    5> $x = gps w* | Send-SmtpMail -to john@doe.com,jane@doe.com -Subject "Test" -Body "Hi" -AttachmentPath \temp\foo.* -whatif
    What if: Performing operation "Send-SmtpMail" on Target "System.Net.Mail.MailMessage".
    6> $x.To |Format-list *
    7> $x | %{"$_"}

    And send the results.
    --
    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.



      My System SpecsSystem Spec

  4. #4


    Jeffrey Snover [MSFT] Guest

    Re: Type formatting question on properties that are collections

    Sorry. Actually I meant to ask for
    5> $x.To | %{"$_"}
    (I'm thinking that they might have a broken ToString(). If you look at the $X , it actually is printing out a list of 2 items but each item appears to be a null string.

    To : {, }

    jps
    "Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message news:OWaU3nQLHHA.4376@TK2MSFTNGP03.phx.gbl...
    Here ya go:

    2> $x.To | Format-List *


    DisplayName :
    User : john
    Host : doe.com
    Address : john@doe.com

    DisplayName :
    User : jane
    Host : doe.com
    Address : jane@doe.com



    3> $x | %{"$_"}
    System.Net.Mail.MailMessage
    4> $x


    From : rkeithhill@comcast.net
    ReplyTo :
    To : {, }
    CC : {}
    Bcc : {}
    Attachments : {foo.bar, foo.bat, foo.bli, foo.config, foo.cs, foo.dll,
    .txt, foo.xml}
    Priority : Normal
    Subject : Test
    IsBodyHtml : False
    Body : Hi

    Hmm, perhaps the MailAddress object is using the DipslayName as its representation? How do I override that behavior for the display of a collection of those objects?

    --
    Keith
    "Jeffrey Snover [MSFT]" <jsnover@ntdev.microsoft.com> wrote in message news:BCCFD5C4-8FDC-4F4E-A5D2-2B9113B07BA4@microsoft.com...
    Do the following:
    5> $x = gps w* | Send-SmtpMail -to john@doe.com,jane@doe.com -Subject "Test" -Body "Hi" -AttachmentPath \temp\foo.* -whatif
    What if: Performing operation "Send-SmtpMail" on Target "System.Net.Mail.MailMessage".
    6> $x.To |Format-list *
    7> $x | %{"$_"}

    And send the results.
    --
    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.



    --
    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.



      My System SpecsSystem Spec

  5. #5


    Keith Hill [MVP] Guest

    Re: Type formatting question on properties that are collections

    5> $x.To | %{"$_"}
    john@doe.com
    jane@doe.com

    6> $x.To | %{$_.ToString()}
    john@doe.com
    jane@doe.com
    7> ,$x.To | %{$_.ToString()}
    john@doe.com, jane@doe.com

    Hmm.. BTW I do have a custom formatter for MailMesage which is the object that contains the MailAddressCollection but I haven't defined anything for MailAddress. Here's the MailMessage view which is just hiding extraneous properties:

    <View>
    <Name>System.Net.Mail.MailMessage</Name>
    <ViewSelectedBy>
    <TypeName>System.Net.Mail.MailMessage</TypeName>
    </ViewSelectedBy>
    <ListControl>
    <ListEntries>
    <ListEntry>
    <ListItems>
    <ListItem>
    <PropertyName>From</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>ReplyTo</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>To</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>CC</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Bcc</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Attachments</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Priority</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Subject</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>IsBodyHtml</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Body</PropertyName>
    </ListItem>
    </ListItems>
    </ListEntry>
    </ListEntries>
    </ListControl>
    </View>

    BTW I still don't see the To entries when I remove this view definition so I don't think this view definition is causing the problem.

    --
    Keith
    "Jeffrey Snover [MSFT]" <jsnover@ntdev.microsoft.com> wrote in message news:21BE4B87-95AC-4238-A1F1-D09CFBA7C6C3@microsoft.com...
    Sorry. Actually I meant to ask for
    5> $x.To | %{"$_"}
    (I'm thinking that they might have a broken ToString(). If you look at the $X , it actually is printing out a list of 2 items but each item appears to be a null string.

    To : {, }

    jps


      My System SpecsSystem Spec

  6. #6


    /\\/\\o\\/\\/ [MVP] Guest

    Re: Type formatting question on properties that are collections

    F.Y.I., same happens on a dataSet ( I noticed on my new Tabcompletion script)

    PoSH>$dsTabExpansion


    RemotingFormat : Xml
    SchemaSerializationMode : IncludeSchema
    CaseSensitive : False
    DefaultViewManager : {System.Data.DataViewManagerListItemTypeDescriptor}
    EnforceConstraints : True
    DataSetName : TabExpansion
    Namespace :
    Prefix :
    ExtendedProperties : {}
    HasErrors : False
    IsInitialized : True
    Locale : en-US
    Site :
    Relations : {}
    Tables : {, , }
    Container :
    DesignMode : False

    PoSH>$dsTabExpansion.tables |% {$_.tablename}
    Custom
    Types
    Wmi

    gr /\/\o\/\/
    http://ThePowerShellGuy.com

    "Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message news:e9C0NTRLHHA.1252@TK2MSFTNGP02.phx.gbl...
    5> $x.To | %{"$_"}
    john@doe.com
    jane@doe.com

    6> $x.To | %{$_.ToString()}
    john@doe.com
    jane@doe.com
    7> ,$x.To | %{$_.ToString()}
    john@doe.com, jane@doe.com

    Hmm.. BTW I do have a custom formatter for MailMesage which is the object that contains the MailAddressCollection but I haven't defined anything for MailAddress. Here's the MailMessage view which is just hiding extraneous properties:

    <View>
    <Name>System.Net.Mail.MailMessage</Name>
    <ViewSelectedBy>
    <TypeName>System.Net.Mail.MailMessage</TypeName>
    </ViewSelectedBy>
    <ListControl>
    <ListEntries>
    <ListEntry>
    <ListItems>
    <ListItem>
    <PropertyName>From</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>ReplyTo</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>To</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>CC</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Bcc</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Attachments</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Priority</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Subject</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>IsBodyHtml</PropertyName>
    </ListItem>
    <ListItem>
    <PropertyName>Body</PropertyName>
    </ListItem>
    </ListItems>
    </ListEntry>
    </ListEntries>
    </ListControl>
    </View>

    BTW I still don't see the To entries when I remove this view definition so I don't think this view definition is causing the problem.

    --
    Keith
    "Jeffrey Snover [MSFT]" <jsnover@ntdev.microsoft.com> wrote in message news:21BE4B87-95AC-4238-A1F1-D09CFBA7C6C3@microsoft.com...
    Sorry. Actually I meant to ask for
    5> $x.To | %{"$_"}
    (I'm thinking that they might have a broken ToString(). If you look at the $X , it actually is printing out a list of 2 items but each item appears to be a null string.

    To : {, }

    jps


      My System SpecsSystem Spec

  7. #7


    Jeffrey Snover [MSFT] Guest

    Re: Type formatting question on properties that are collections

    Sounds like it is time to file a bug.

    --
    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.



      My System SpecsSystem Spec

  8. #8


    Keith Hill [MVP] Guest

    Re: Type formatting question on properties that are collections

    Done:

    https://connect.microsoft.com/feedba...9112&SiteID=99

    --
    Keith
    "Jeffrey Snover [MSFT]" <jsnover@ntdev.microsoft.com> wrote in message news:2DBC7556-E213-4E3E-AFC0-E0F4F151C10E@microsoft.com...
    Sounds like it is time to file a bug.


      My System SpecsSystem Spec

Type formatting question on properties that are collections problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
group-object formatting question Uwe Ziegenhagen PowerShell 2 30 Dec 2009
Formatting question Jan Egil R. PowerShell 0 09 May 2009
PS & Excel2003: dual question about formatting Jeroen PowerShell 5 06 Feb 2009
Installing on a RAID drive -- question about formatting Daervon Vista installation & setup 1 05 Mar 2007
Confused getting properties of Collections of one vs. many =?Utf-8?B?TWlrZSBCcmlkZ2U=?= bridgecanada _ com> PowerShell 19 04 Sep 2006