VMware datastore utilization report

Get vmware datastore report in Email.

###############################
# VMware Datastorereport #
# anupampushkar.wordpress.com #
###############################
Add-PSSnapin VMware.VimAutomation.Core -erroraction silentlycontinue
#give user Name and password
Connect-VIServer -Server 10.0.8.96 -Protocol https -User XXXXXXXX -Password XXXXXXX
function execute
{

$dateo= get-date
$body += ‘<html>’
$body += ‘<body>’
$msg6 = “Datastore Details”
$body += ‘<table border=”1″ style=”font-family:Tahoma;font-size:77%” align=”center” cellpadding=”3″ cellspacing=”1″style=”border-top: 1px solid#C0C0C0;border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;border-bottom: 1px solid #C0C0C0;”>’
$body += ‘<tr>’
$body += ‘<td colspan=7 style=”font-family:Tahoma;font-size:72%” border=”1″ bgcolor=”#FFCC00″ align=”Center” >’+ $msg6 +'</td>’
$body += ‘</tr>’
$body += ‘<tr>’
$body += ‘<td border=”1″ style=”font-family:Tahoma;font-size:75%” bgcolor=”#7F7A75″ align=”left” valign=”top” style=”border-bottom: 1px solid #C0C0C0;”width=”20%”><div align=”center”>Name</div></td>’
$body += ‘<td border=”1″ style=”font-family:Tahoma;font-size:75%” bgcolor=”#7F7A75″ align=”left” valign=”top” style=”border-bottom: 1px solid #C0C0C0;”width=”10%”><div align=”center”>Capacity in GB</div></td>’
$body += ‘<td border=”1″ style=”font-family:Tahoma;font-size:75%” bgcolor=”#7F7A75″ align=”left” valign=”top” style=”border-bottom: 1px solid #C0C0C0;”width=”10%”><div align=”center”>FreeSpace GB</div></td>’
$body += ‘<td border=”1″ style=”font-family:Tahoma;font-size:75%” bgcolor=”#7F7A75″ align=”left” valign=”top” style=”border-bottom: 1px solid #C0C0C0;”width=”20%”><div align=”center”>Used Space</div></td>’
$body += ‘<td border=”1″ style=”font-family:Tahoma;font-size:75%” bgcolor=”#7F7A75″ align=”left” valign=”top” style=”border-bottom: 1px solid #C0C0C0;”width=”20%”><div align=”center”>%Free</div></td>’
$body += ‘</tr>’
$e = 1
$a
$b = Get-Datastore
#$b
$d = 1
foreach($item in $b)
{
$presentfre=$item.CapacityGB – $item.FreeSpaceGB
write-host “Run”
$body +='<tr>’
$body += ‘<td style=”font-family:Tahoma;font-size:72%” align=”left” border=”1″ >’ + $item.Name + ‘</td>’
$body += ‘<td style=”font-family:Tahoma;font-size:72%” align=”Center” border=”1″ >’+ $item.CapacityGB +'</td>’
$body += ‘<td style=”font-family:Tahoma;font-size:72%” align=”Center” border=”1″ >’+ $item.FreeSpaceGB +'</td>’
$body += ‘<td style=”font-family:Tahoma;font-size:72%” align=”Center” border=”1″ >’+ $(“{0:N2}” -f(($item.CapacityGB) -($item.FreeSpaceGB)))+'</td>’
$body += ‘<td style=”font-family:Tahoma;font-size:72%” align=”Center” border=”1″ >’+ $(“{0:N2}” -f(($item.FreeSpaceGB) /($item.CapacityGB)*100))+$symo+'</td>’
}
$body += ‘</table>’
$body += ‘</body>’
$body += ‘</html>’
if($e -eq 1)
{
$SMTPClient = new-object System.Net.Mail.smtpClient
$MailMessage = new-object System.Net.Mail.MailMessage
$MailMessage.Subject = “VMware Datastore report On $dateo”
$MailMessage.Body = “$body”
#give the Email ID from which email will be sent
$MailMessage.Sender = “DailyReports@############.com”
#give the Email ID from which email will be sent
$MailMessage.From = “DailyReports@XXXXXXXXX.com”
# Give to
$MailMessage.To.add(“XXXXXXXXXXXXXXXXXXXXXXXX”)
#give CC
$MailMessage.Cc.add(“XXXXXXXXXXXXXXXXXXXXXXXX”)
$MailMessage.IsBodyHTML = $true
#give SMTP address
$SMTPClient.host = “XXXXXXXXXXXXXXXXXXXXXXXXXXX”
$SMTPClient.Send($MailMessage)
}
} #function close
execute

Save the above as filename.ps1

hope you know how to run .ps1 files or how to schedule it. if now please leave the comment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s