Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 178257

Powershell/PowerCLI Dynamic Email Message Body

$
0
0

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 += "<FONTCOLOR=black>VMware HealthCheck vCenter2</FONT><BR><BR>"  + ` 
"<B><FONTCOLOR=black>Snapshots Active</FONT></B><BR>" + ` 
"<B><FONTCOLOR=black>VM Name</FONT></B>"+` 
"<B><FONTCOLOR=black>                                      ` Name</FONT></B>"+` "<B><FONTCOLOR=black>                                      ` Created</FONT></B><BR>"+` "<FONTCOLOR=Red>"+$array0+"</FONT>"+` "<FONTCOLOR=Red>                                    "+$array1+"</FONT>"+` "<FONTCOLOR=Red>                                    "+$array2+"</FONT><BR><BR>"+` "<B><FONTCOLOR=black>CDROMS Connected (Bad Habit)</FONT></B><BR>"+"<B><FONTCOLOR=black>VM Name</FONT></B><BR>"+"<FONTCOLOR=Red>"+$array3+"</FONT>" 
$i++ 
$j++
} Until (($array0[$i] -eq $null ) -or ($array3[$j] -eq $null))

The output i get is:

From: VMware Healtcheck

Sent: Thursday, June 20, 2013 1:26 PM

To: Me

Subject: VMware Health UPIvCenter2

 

VMware HealthCheck vCenter2

 

Snapshots Active

VM Name Name Created

VEEAM1 VEEAM1 Test1 Test2 06/20/2013 09:06:09 06/20/2013 09:31:15

 

CDROMS Connected (Bad Habit)

VM Name

MAILGATE

 

And would like to have is:

From: VMware Healtcheck

Sent: Thursday, June 20, 2013 1:26 PM

To: Me

Subject: VMware Health UPIvCenter2

 

VMware HealthCheck vCenter2

 

Snapshots Active

VM Name          Name          Created

VEEAM1           Test1           06/20/2013 09:06:09

VEEAM1           Test2           06/20/2013 09:31:15

 

CDROMS Connected (Bad Habit)

VM Name

MAILGATE

 

NOTE:  I can have multiple snapshots or multiple VMs with CD Roms connected. Thanks for your help.


Viewing all articles
Browse latest Browse all 178257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>