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:
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?
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
}