Powershell: Dynamic Email Message Body
-
Hello, not sure if I am in the right spot to post my question about PowerShell/PowerCLI I have a script in powershell that will send an email to an outlook client. The msg body will have values regarding to two things: Active Snapshots in the virtual environment and CD ROMs attached to the VMs. Let's talk when the email reports more that one CDRoms attached, how do I increase or decrease the msg body depending of the results gathered from the virtual environment ? So, far I have this code:
if (($Snapshots -eq "yes") -or ($cdroms -eq "yes"))
{
$array0 = @()
$array1 = @()
$array2 = @()
$array3 = @()
start-sleep 1
connect-VIServer $vcserver
$array0 += Get-VM | get-snapshot | %{$_.VM.Name}
$array1 += Get-VM | get-snapshot | select-object -expandproperty Name
$array2 += Get-VM | get-snapshot | select-object -expandproperty Created
$array3 =@(Get-VM | where { $_ | Get-CDdrive | where { $_.ConnectionState.Connected -eq "true" } } | Select-object -ExpandProperty Name)
$i = 0
$j = 0
Do {
$msg.Body += "<FONT COLOR=black>VMware HealthCheck vCenter2</FONT><BR><BR>" + `
"<B><FONT COLOR=black>Snapshots Active</FONT></B><BR>" + `
"<B><FONT COLOR=black>VM Name</FONT></B>"+`
"<B><FONT COLOR=black> `
Name</FONT></B>"+`
"<B><FONT COLOR=black> `
Created</FONT></B><BR>"+`
"<FONT COLOR=Red>"+$array0+"</FONT>" -
Hello, not sure if I am in the right spot to post my question about PowerShell/PowerCLI I have a script in powershell that will send an email to an outlook client. The msg body will have values regarding to two things: Active Snapshots in the virtual environment and CD ROMs attached to the VMs. Let's talk when the email reports more that one CDRoms attached, how do I increase or decrease the msg body depending of the results gathered from the virtual environment ? So, far I have this code:
if (($Snapshots -eq "yes") -or ($cdroms -eq "yes"))
{
$array0 = @()
$array1 = @()
$array2 = @()
$array3 = @()
start-sleep 1
connect-VIServer $vcserver
$array0 += Get-VM | get-snapshot | %{$_.VM.Name}
$array1 += Get-VM | get-snapshot | select-object -expandproperty Name
$array2 += Get-VM | get-snapshot | select-object -expandproperty Created
$array3 =@(Get-VM | where { $_ | Get-CDdrive | where { $_.ConnectionState.Connected -eq "true" } } | Select-object -ExpandProperty Name)
$i = 0
$j = 0
Do {
$msg.Body += "<FONT COLOR=black>VMware HealthCheck vCenter2</FONT><BR><BR>" + `
"<B><FONT COLOR=black>Snapshots Active</FONT></B><BR>" + `
"<B><FONT COLOR=black>VM Name</FONT></B>"+`
"<B><FONT COLOR=black> `
Name</FONT></B>"+`
"<B><FONT COLOR=black> `
Created</FONT></B><BR>"+`
"<FONT COLOR=Red>"+$array0+"</FONT>"Its quite tricky, but try to post this question at likeplum. I always get good answers there to my computer/programming issues and questions. They have programmers online to help you now. You can get a great answer to your question so fast. https://www.likeplum.com/help/programming?aid=3321