SAPIENScripter Posted December 14, 2006 Report Share Posted December 14, 2006 I was testing out Send-Mail and came across something I thought I'd share as a tip. If you are piping the output of a cmdlet straight to Send-Mail, you might not get the result you expect. If you run a command like get-process |Send-mail, the resulting mail message will look like this: Microsoft.PowerShell.Commands.Internal.Format.FormatStartDataMicrosoft.PowerShell.Commands.Internal.Format.GroupStartDataMicrosoft.PowerShell.Commands.Internal.Format.FormatEntryDataMicrosoft.PowerShell.Commands.Internal.Format.FormatEntryDataMicrosoft.PowerShell.Commands.Internal.Format.FormatEntryData You have to remember to pipe the output to Out-String and then to Send-mail get-process | Out-String | Send-Mail Unless Send-mail is tweaked so that any object passed to it is converted to a string so you don't have to think about it. Quote Link to comment Share on other sites More sharing options...
JuanC Posted December 15, 2006 Report Share Posted December 15, 2006 We have an implementation that follows your recommendation, it accepts both get-process | send-mail get-process | out-string | send-mail There is an interesting scenario we wanted to share with you, what would you expect is the output of the following command dir *.csv | send-mail a) Is it an email with the text output generated by get-childitem Is it an email that includes the csv as attachments? I am guessing you can say "give me both and a parameter that specifies which method to use" but we want to know which is the behavior you expect to be the default. Obviously if you do "dir *.csv | out-string | send-mail" we will send the output generated by get-childitem as we will not get the real files. JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.