Virtual Machine Stats
############################ Virtual Machine Stats Report #################################
############################## Created By Shobhit Mathur ###################################
############################## MAR - Modify As Required ####################################
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$VIServers= "XXX" ###MAR###
Connect-VIServer $VIServers -User <username> -Password <password> ###MAR###
##########################################################################
$today = get-Date
$reportFileX = Get-Date -UFormat "E:\VM-Report-%Y%b%d@%I%M%p.html" ###MAR###
##########################################################################
$Shox1=@"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Font-Size: 8pt;Font-Family: Tahoma, sans-serif;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #bc64ed;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
##########################################################################
$PowerState = @{N="Power State" ; E={$_.powerState}}
$UpTime = @{N="Up Time";E={$Timespan = New-Timespan -Seconds (Get-Stat -Entity $_.Name -Stat "sys.uptime.latest" -Realtime -MaxSamples 1).Value
"" + $Timespan.Days + " Days, "+ $Timespan.Hours + " Hours, " +$Timespan.Minutes + " Minutes"}}
$NumCPU = @{N="CPU" ; E={$_.NumCPU}}
$NumMEM = @{N="Mem (GB)" ; E={$_.MemoryGB}}
$CPUAVG = @{N="CPU.Avg (%)" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$MEMAVG = @{N="Mem.Avg (%)" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$NETAVG = @{N="Net.Avg (KBps)" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$IPADD1 = @{N="IPADD1";E={@($_.guest.IPAddress[0])}}
$IPADD2 = @{N="IPADD2";E={@($_.guest.IPAddress[1])}}
$IPADD3 = @{N="IPADD3";E={@($_.guest.IPAddress[2])}}
$Sho1 += Get-VM | Select Name,$PowerState,$uptime,$NumCPU,$NumMem,$CPUAVG,$MEMAVG,$NETAVG,$IPADD1,$IPADD2,$IPADD3 | ConvertTo-Html -AS Table -Fragment
$StatusColor1 = @{PoweredOff = ' bgcolor="Red">PoweredOff<';PoweredOn = ' bgcolor="lime">PoweredOn<';}
$StatusColor1.Keys | foreach { $Sho1 = $Sho1 -replace ">$_<",($StatusColor1.$_) }
[String]$Sho11 = ConvertTo-Html -head $Shox1 -body $Sho1
##########################################################################
Disconnect-VIServer $VIServers -Force -Confirm:$false
##########################################################################
$From = "<email>" ###MAR###
$To = "<email>" ###MAR###
$Cc = "<email>" ###MAR###
$BCC = "smathur3@in.ibm.com" ###MAR###
$Subject = "VM Report" ###MAR###
$Body1 = "<p>Dear Team, <br><br> ###MAR###
Attached is the HPAAS Core VM Report for today.</p>"
$Body0D = "<p><h4>
<b>"VC Name"</b> VMs.
</h4></p>"
$ShoX += "<p><Font Color = Blue><h1><b><center>VM Report</Font></h1></center></b></p>"
$ShoX += "<center>$today</center>"
$ShoX += $Body1D + $Sho11
$ShoX | out-file $reportFileX
$SMTPServer = "XXX" ###MAR###
$SMTPPort = "XXX" ###MAR###
$HTMLBody = $Body1
#Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer -Attachments $reportFileX
##########################################################################
############################ Virtual Machine Stats Report #################################
############################## Created By Shobhit Mathur ###################################
############################## MAR - Modify As Required ####################################
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$VIServers= "XXX" ###MAR###
Connect-VIServer $VIServers -User <username> -Password <password> ###MAR###
##########################################################################
$today = get-Date
$reportFileX = Get-Date -UFormat "E:\VM-Report-%Y%b%d@%I%M%p.html" ###MAR###
##########################################################################
$Shox1=@"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Font-Size: 8pt;Font-Family: Tahoma, sans-serif;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #bc64ed;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
##########################################################################
$PowerState = @{N="Power State" ; E={$_.powerState}}
$UpTime = @{N="Up Time";E={$Timespan = New-Timespan -Seconds (Get-Stat -Entity $_.Name -Stat "sys.uptime.latest" -Realtime -MaxSamples 1).Value
"" + $Timespan.Days + " Days, "+ $Timespan.Hours + " Hours, " +$Timespan.Minutes + " Minutes"}}
$NumCPU = @{N="CPU" ; E={$_.NumCPU}}
$NumMEM = @{N="Mem (GB)" ; E={$_.MemoryGB}}
$CPUAVG = @{N="CPU.Avg (%)" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$MEMAVG = @{N="Mem.Avg (%)" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$NETAVG = @{N="Net.Avg (KBps)" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-1) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}
$IPADD1 = @{N="IPADD1";E={@($_.guest.IPAddress[0])}}
$IPADD2 = @{N="IPADD2";E={@($_.guest.IPAddress[1])}}
$IPADD3 = @{N="IPADD3";E={@($_.guest.IPAddress[2])}}
$Sho1 += Get-VM | Select Name,$PowerState,$uptime,$NumCPU,$NumMem,$CPUAVG,$MEMAVG,$NETAVG,$IPADD1,$IPADD2,$IPADD3 | ConvertTo-Html -AS Table -Fragment
$StatusColor1 = @{PoweredOff = ' bgcolor="Red">PoweredOff<';PoweredOn = ' bgcolor="lime">PoweredOn<';}
$StatusColor1.Keys | foreach { $Sho1 = $Sho1 -replace ">$_<",($StatusColor1.$_) }
[String]$Sho11 = ConvertTo-Html -head $Shox1 -body $Sho1
##########################################################################
Disconnect-VIServer $VIServers -Force -Confirm:$false
##########################################################################
$From = "<email>" ###MAR###
$To = "<email>" ###MAR###
$Cc = "<email>" ###MAR###
$BCC = "smathur3@in.ibm.com" ###MAR###
$Subject = "VM Report" ###MAR###
$Body1 = "<p>Dear Team, <br><br> ###MAR###
Attached is the HPAAS Core VM Report for today.</p>"
$Body0D = "<p><h4>
<b>"VC Name"</b> VMs.
</h4></p>"
$ShoX += "<p><Font Color = Blue><h1><b><center>VM Report</Font></h1></center></b></p>"
$ShoX += "<center>$today</center>"
$ShoX += $Body1D + $Sho11
$ShoX | out-file $reportFileX
$SMTPServer = "XXX" ###MAR###
$SMTPPort = "XXX" ###MAR###
$HTMLBody = $Body1
#Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer -Attachments $reportFileX
##########################################################################
No comments:
Post a Comment