Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Type formatting question on properties that are collections

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 12-30-2006   #1 (permalink)
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
Old 12-31-2006   #2 (permalink)
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
Old 12-31-2006   #3 (permalink)
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
Old 12-31-2006   #4 (permalink)
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
Old 12-31-2006   #5 (permalink)
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
Old 12-31-2006   #6 (permalink)
/\\/\\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
Old 12-31-2006   #7 (permalink)
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
Old 01-01-2007   #8 (permalink)
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
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant type question marks or slashes *Carla* Live Messenger 1 02-06-2008 11:53 AM
Installing Vista on a RAID drive -- question regarding formatting Daervon Vista General 1 03-05-2007 12:50 PM
Installing on a RAID drive -- question about formatting Daervon Vista installation & setup 1 03-05-2007 12:05 PM
Clear Type tuner question... Alex Vista General 5 02-02-2007 12:02 PM
Confused getting properties of Collections of one vs. many =?Utf-8?B?TWlrZSBCcmlkZ2U=?= bridgecanada _ com> PowerShell 19 09-04-2006 11:26 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51