Powershell Emailing Issue

Associate
Joined
2 Aug 2005
Posts
589
I am writing a script which queries my vCenter and looks for all VMs that don't have an environment tag. Essentially this tag is used in Veeam to backup our VMs. If it doesn't have a tag, it doesn't back up.

The issue I'm having is that $noTagVMs is an array which contains all the VMs that don't have a tag. When outputting this to an email, I would like each object within the array to be displayed on a new line. Currently the output is like this:

The machines listed below haven't got an environment tag in vSphere. In the mean time they have been tagged as 'Development' to ensure they'll be backed up, but please review this if the classification is incorrect.
TestVM1 TestVM2

I have looked at using `n and -join and god knows what else, but I can't seem to get it working correctly - any suggestions?

Code:
Function sendEmail ($noTagVMs) {

#Variables
$smtpTo = "[email protected]"
$smtpFrom = "[email protected]"
$messageSubject = "Test Email"
$smtpServer = "mailserver.domain.com"
$messageBody = "The machines listed below haven't got an environment tag in vSphere. In the mean time they have been tagged as 'Development' to ensure they'll be backed up, but please review this if the classification is incorrect.<br /> $($noTagVMs.name)"


Send-MailMessage -To $smtpTo -From $smtpFrom -Subject $messageSubject -Body $messageBody -BodyAsHtml -SmtpServer $smtpServer
}
 
bit of a hack but something as simple as replacing the spaces in the string with <br />?
ie
($noTagVMs.name -replace (" ", "<br />"))
 
Some useful info in here I will be using myself. I have a bunch of Powershell scripts that run nightly doing tidy up work for old AD users and O365 mailing lists etc. I've got everything logged on the server in log files but like the idea of having a summery email from each of the scripts like users marked for deletion, users added/removed from mailing lists, display name changes etc
 
Back
Top Bottom