I’m really new with PowerShell, and I’m trying to do what seems like a very simple task but for the life of me cannot wrap my head around the behavior.
All I am trying to do is connect to one of our VCenter servers, query the datastore information and send the output to us via email.
I get the email but it only lists the one column (datastore names) and puts only that in the body of the email. If I just type $datastore by itself, I get all the data including the free space/available space which is what I want. All of my Google searches keeps hinting around something to do with HTML vs. plain-text as they relate to tables etc... but adding or removing the "-BodyAsHTML" does not impact this.
Can anyone see what I’m missing from my 2 lines here? Any help would be appreciated.
Hi! Thanks for the suggestion. I’m not 100% certain on the proper syntax of that commandlet or really more so where to insert it. I seemed to have received the same output in the email using the covertto-html command or not.
To answer your question - It doesn’t look like the output of get-datastore is in HTML at all, so I might just be going down a bunny trail thinking it had something to do with HTML or not. Thanks again for the suggestion!
I think you have two options. Either you omit the parameter -BodyAsHtml of Send-MailMessage and send the data as plain text or you figure out how to use the cmdlet ConvertTo-Html. You should always read the complete help including the examples for every cmdlet you’re about to use to learn how to use it.
You are returning an object, so it would simpler to use ConvertTo-HTML to convert it into a table. Passing credentials is only required if the SMTP server is not setup as anonymous, but if it does require credentials it need to be a credential object. Lastly, a kitten is killed every time you don’t use splatting for long commands in Powershell
I have found that when I do not use splatting as Rob suggests, I get odd results with the Send-MailMessage command in PowerShell. Just something to look at if you do not choose to follow the recommendation and experience inconsistencies.
Thank you Sir! I really appreciate your help with this. This worked perfectly. Now that I have this, I can tweak it to use it in other ways. I appreciate you giving me what I need along with resource suggestion. Much more helpful than the old Linux-Forum “GO RTFM” response I’ve been getting.