Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 183671

How to output the result of PowerCLI command in an email ?

$
0
0


Hi Everyone,

 

Can someone provide me help with this example. I'm starting to work with PowerCLI and I have difficulty to output my result in an email.

How can I store my result in array and import the data in HTML in an email ?

From the example below, I don't see any result in the email from the powercli command " Get-VM | Select-Object Name, NumCPU, MemoryMB, ProvisionedSpaceGB"

Do I need to create a loop to extract the result ?

 

#-------------------------CHANGE THESE VALUES--------------------------------
$SMTPServer = "SMTP.toto.com"
$vCenterServerName1 = "vsphere1.toto.com"
$ToAddress = lady@toto.com
#-----------------------------------------------------------------------------

$Title = "Connection settings for vCenter"
$Author = "Lady"
$Header =  "Connection Settings"

$Login = account@toto.com# for LAFAM domain
$Password = "xxxxxxxxxx#

add-pssnapin VMware.VimAutomation.Core

$HTMLHeader = "<HTML><TITLE> VMware report </TITLE>"
$HTMLFooter = "Made with POWERSHELL Script 2.0 - Version of the script " + $ScriptVersion + "</HTML>"

$ScriptVersion = "v1.0"
$Subject = "VMware Report - VM Inventory "
$FromAddress = "VMware" + "@toto.com"

$ColorArray = "Red", "Orange", "Purple", "Blue", "Olive", "SlateGrey", "Orange", "Purple", "Blue", "Olive"
$ColorArrayIndex = 0

$HTMLHeader = "<HTML><TITLE> VMware Report for " + $vCenterServerName1 " </TITLE>"
$HTMLFooter = "Made with POWERCLI Script 5.0 - " +  $Author + ".<br><br>"
$HTMLFooter += "<B>NOTE:</B> $Date </HTML>"


$HTMLBody = "<BODY>"

$vCenter_inventory = @(Get-VM | Select-Object Name, NumCPU, MemoryMB, ProvisionedSpaceGB)

 

################################### OUTPUT #######################################

# HEADER
$HTMLBody += CreateHeader ("REPORT FOR <font color=Blue><b> vCENTER " + $vCenterServerName1 + "</font></b><br>")

# INTRO TEXT

$HTMLBody += "<br><br>"
$HTMLBody += $vCenter_inventory


########################### SEND REPORT BY E-MAIL #################################
$HTMLBody += "</BODY>" # Close HTML Body
$HTMLPage = $HTMLHeader + $HTMLBody + $HTMLFooter
Send-Mailmessage -From $FromAddress -To $ToAddress -Subject $Subject -BodyAsHTML -Body $HTMLPage -Priority Normal -SmtpServer $SMTPServer
Write-Host "Report has been sent by E-mail to " $ToAddress " from " $FromAddress
################################### CLEANUP #######################################

$HTMLHeader = ""
$HTMLBody = ""
$HTMLFooter = ""
$HTMLPage = ""
$vCenter1_Inventory = ""
$vCenterServerName1 = ""


Viewing all articles
Browse latest Browse all 183671

Trending Articles



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