Daily Health check

 Alarms
###############################################################################
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.Storage -ErrorAction SilentlyContinue
$YYYYMMDD = Get-Date -format 'yyyyMMdd'
$today = get-Date
#----------------------#
# Create the HTML file #
#----------------------#
$ReportFile2 = Get-Date -UFormat "E:\Sho\Reports\junk\DHC-%Y%b%d@%I%M%p.html"
echo $ReportFile2 
New-Item -ItemType file $ReportFile2 -Force
#-----------------#
# Define the HTML #
#-----------------#
Add-Content $ReportFile2 "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"
Add-Content $ReportFile2 "<html xmlns='http://www.w3.org/1999/xhtml'>"
Add-Content $ReportFile2 "<head>"
Add-Content $ReportFile2 "<style type='text/css'>"
Add-Content $ReportFile2 "div.content {"
Add-Content $ReportFile2 "    border: #000 solid 3px;"
Add-Content $ReportFile2 "    clear: left;"
Add-Content $ReportFile2 "    padding: 1em;"
Add-Content $ReportFile2 "    font-family: Tahoma;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "div.content.inactive {"
Add-Content $ReportFile2 " display: none;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc {"
Add-Content $ReportFile2 "    height: 2em;"
Add-Content $ReportFile2 "    list-style: none;"
Add-Content $ReportFile2 "    margin: 0;"
Add-Content $ReportFile2 "    padding: 0;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc a {"
Add-Content $ReportFile2 "    background: #bdf url(tabs.gif);"
Add-Content $ReportFile2 "    color: #000;"
Add-Content $ReportFile2 "    display: block;"
Add-Content $ReportFile2 "    float: left;"
Add-Content $ReportFile2 "    height: 2em;"
Add-Content $ReportFile2 "    padding-left: 10px;"
Add-Content $ReportFile2 "    text-decoration: none;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc a:hover {"
Add-Content $ReportFile2 "    background-color: #3af;"
Add-Content $ReportFile2 "    background-position: 0 -120px;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc a:hover span {"
Add-Content $ReportFile2 "    background-position: 100% -120px;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc li {"
Add-Content $ReportFile2 "    float: left;"
Add-Content $ReportFile2 "    margin: 0 1px 0 0;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc li a.active {"
Add-Content $ReportFile2 "    background-color: #48f;"
Add-Content $ReportFile2 "    background-position: 0 -60px;"
Add-Content $ReportFile2 "    color: #fff;"
Add-Content $ReportFile2 "    font-weight: bold;"
Add-Content $ReportFile2 "    font-family: Tahoma;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc li a.active span {"
Add-Content $ReportFile2 "    background-position: 100% -60px;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "ol#toc span {"
Add-Content $ReportFile2 "    background: url(tabs.gif) 100% 0;"
Add-Content $ReportFile2 "    display: block;"
Add-Content $ReportFile2 "    line-height: 2em;"
Add-Content $ReportFile2 "    padding-right: 10px;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "</style>"
#------------------#
# Define HTML Tabs #
#------------------#
Add-Content $ReportFile2 "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
Add-Content $ReportFile2 "<title> $VIServers Health Check Report</title>"
Add-Content $ReportFile2 "</head>"
Add-Content $ReportFile2 "<body>"
Add-Content $ReportFile2 "<body style=font-family:Tahoma>"
Add-Content $ReportFile2 "<p><Font Color = Blue><h1><b><center>Westpac Daily Health Check Report</Font></h1></center></b></p>"
Add-Content $ReportFile2 "<center>$today (GMT+10)</center>"
Add-Content $ReportFile2 "<ol id='toc'>"    
Add-Content $ReportFile2 "<li><a href='#page-1'><span>AU2012SP0501Z</span></a></li>" 
Add-Content $ReportFile2 "<li><a href='#page-2'><span>AU2106SP0700</span></a></li>"
Add-Content $ReportFile2 "<li><a href='#page-3'><span>AU2004SP0501Z</span></a></li>"   
Add-Content $ReportFile2 "<li><a href='#page-4'><span>AU2004SP0700</span></a></li>"
#Add-Content $ReportFile2 "<li><a href='#page-5'><span>AUYXUAP435WBC32</span></a></li>"
Add-Content $ReportFile2 "<li><a href='#page-6'><span>AU2004SP0837</span></a></li>"
Add-Content $ReportFile2 "</ol>"
#<p><Font Color = Blue><h1><b><center>Master Server Report</Font></h1></center></b></p>
#-------------------------#
# Define HTML Table Style #
#-------------------------#
#Overall background Color background-color:#99FF33(green),F9FF33(yellow) FCFF99(faded yellow) 7fff00 (light green) #
Add-Content $ReportFile2 "<style>BODY{background-color:#7fff00;}TABLE{font-family: Tahoma;font-size: 9pt;border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}TH{border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color:#3af}TD{border-width: 2px;padding: 2px;border-style: solid;border-color: black;background-color:white}</style>"
#################################################################################
#-------------------------------#
# Tab 1, AU2012SP0501Z #
#-------------------------------#
#--------------#
# Start of Tab 1 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-1'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AU2012SP0501Z"
Connect-VIServer $VIServers -User administrator@vsphere.local -Password "Th30ldpwd"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers<br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
Add-Content $ReportFile2 "Only clusters WSDC00ENPR03 & WSDC00CPRD03 are allowed at Manual DRS"
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 1 #
#--------------#
Add-Content $ReportFile2 "</div>"

#################################################################################
#--------------------------#
# Tab 2, AU2106SP0700 #
#--------------------------#
#--------------#
# Start of Tab 2 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-2'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AU2106SP0700"
Connect-VIServer $VIServers -User administrator@vsphere.local -Password "Th30ldpwd"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers<br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 2 #
#--------------#
Add-Content $ReportFile2 "</div>"

#################################################################################
#--------------------------#
# Tab 3, AU2004SP0501Z #
#--------------------------#
#--------------#
# Start of Tab 3 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-3'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AU2004SP0501Z"
Connect-VIServer $VIServers -User administrator@vsphere.local -Password "Th30ldpwd"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers<br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
Add-Content $ReportFile2 "Only Cluster RCC00BPRD03 is allowed at Manual DRS"
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 3 #
#--------------#
Add-Content $ReportFile2 "</div>"
#################################################################################
#--------------------------#
# Tab 4, AU2004SP0700           #
#--------------------------#
#--------------#
# Start of Tab 4 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-4'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AU2004SP0700"
Connect-VIServer $VIServers -User administrator@vsphere.local -Password "Th30ldpwd"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers <br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 4 #
#--------------#
Add-Content $ReportFile2 "</div>"
<#################################################################################
#--------------------------#
# Tab 5, AUYXUAP435WBC32 #
#--------------------------#
#--------------#
# Start of Tab 5 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-5'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AUYXUAP435WBC32"
Connect-VIServer $VIServers -User "root" -Password "VMware123"
# Connect-VIServer AUYXUAP435WBC32 -User "root" -Password "VMware123"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers <br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 5 #
#--------------#
Add-Content $ReportFile2 "</div>"
/#>
#################################################################################
#--------------------------#
# Tab 6, AU2004SP0837 #
#--------------------------#
#--------------#
# Start of Tab 6 #
#--------------#
Add-Content $ReportFile2 "<div class='content' id='page-6'>"
#------------------------------#
# Summary #
#------------------------------#
$VIServers = "AU2004SP0837"
Connect-VIServer $VIServers -User administrator@vsphere.local -Password "Th30ldpwd"
$vmz = (get-vm).count
$esx = (get-vmhost).count
$cluster = (get-cluster).count
$VMs = Get-VM  
$PoweredOnVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOn"})
$POVM = ($PoweredOnVM).count
$PoweredOffVM = @($VMs | Where-Object {$_.PowerState -eq "PoweredOff"})
Add-Content $ReportFile2 "<p><b>Date          :</b> $today<br></p>"
Add-Content $ReportFile2 "<p><b>vCenter Server:</b> $VIServers <br></p>"
Add-Content $ReportFile2 "<p><b>No. of Cluster:</b> $cluster<br></p>"
Add-Content $ReportFile2 "<p><b>No. of ESXi   :</b> $esx<br></p>"
Add-Content $ReportFile2 "<p><b>Total VMs     :</b> $vmz<br></p>"
Add-Content $ReportFile2 "<p><b>Powered-On VMs:</b> $POVM <br><br></p>"
#------------------------------#
# HA/DRS #
#------------------------------#
Add-Content $ReportFile2 "<H2>HA/DRS Stats</H2>"
Get-Cluster "*"| Select-Object -Property Name,HAEnabled,HAAdmissionControlEnabled,DrsEnabled,DrsAutomationLevel | ConvertTo-Html -Fragment | Out-File hadrs.html
Get-Content hadrs.html | Add-Content $ReportFile2
#------------------------
# ESXi CPU/Memory #
#------------------------
Add-Content $ReportFile2 "<H2>ESXi CPU/MEM</H2>"
Get-VMHost|
Select Name,
    @{N=“Cluster“;E={Get-Cluster -VMHost $_}},
    @{N=“VMs“;E={($_ | Get-VM).Count}},
    @{N=“Powered-On VMs“;E={($_ | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} ).Count}},
    @{N="State";E={$_.ConnectionState}},
#@{N="Status";E={$_.ExtensionData.Summary.OverallStatus}},
@{N="CPU Capacity (GHZ)";E={[math]::Round($_.CpuTotalMhz/1000,0)}},
    @{N="CPU Used (GHZ)";E={[math]::Round($_.CpuUsageMhz/1000,2)}},
@{N="CPU Used (%)";E={[math]::Round(($_.CpuUsageMhz*100/$_.CpuTotalMhz),0)}},
@{N="Memory Size (GB)";E={[math]::Round($_.MemoryTotalGB,0)}},
    @{N="Memory Used (GB)";E={[math]::Round($_.MemoryUsageGB,0)}},
@{N="Memory Used (%)";E={[math]::Round(($_.MemoryUsageGB*100/$_.MemoryTotalGB),0)}}`
 | ConvertTo-Html -Fragment | Out-File esxicpumem.html
Get-Content esxicpumem.html | Add-Content $ReportFile2
#------------------------
# All Alarms #
#------------------------
Add-Content $ReportFile2 "<H2>Alarms as on $today </H2>"
$HostList =@"
<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 {bord
er-width: 1px;padding: 3px;border-style: solid;border-color: black;} 
</style>
"@

$hosts1 = Get-vm | Get-View
$hosts2 = Get-vmhost | Get-View
$hosts3 = Get-cluster | Get-View
$hosts4 = Get-datastore | Get-View
foreach ($esxihost in $hosts1){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts2){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts3){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
foreach ($esxihost in $hosts4){                             #For each Host
   foreach($triggered in $esxihost.TriggeredAlarmState){             #For each triggered alarm of each host
           $arrayline={} | Select HostName, AlarmType, AlarmInformations     #Initialize line
           $alarmDefinition = Get-View -Id $triggered.Alarm             #Get info on Alarm
           $arrayline.HostName = $esxihost.Name                 #Get host which has this alarm triggered
        $arrayline.AlarmType = $triggered.OverallStatus             #Get if this is a Warning or an Alert
           $arrayline.AlarmInformations = $alarmDefinition.Info.Name         #Get infos about alarm
           $HostList += $arrayline                         #Add line to array
        $HostList = @($HostList)                         #Post-Declare this is an array
   }
}
$HostList |select HostName, AlarmType, AlarmInformations | ConvertTo-Html -Fragment | Out-File esxialarms.html
Get-Content esxialarms.html | Add-Content $ReportFile2
#-------------------#
# Remove temp files #
#-------------------#
Remove-Item hadrs.html 
Remove-Item esxicpumem.html 
Remove-Item esxialarms.html
Disconnect-VIServer $VIServers -Force -Confirm:$false
#--------------#
# End of Tab 6 #
#--------------#
Add-Content $ReportFile2 "</div>"
#################################################################################
#--------------------------#
# End of Reportfile #
#--------------------------#
Add-Content $ReportFile2 "<p><br><br><center><h10>This is script generated report, hence for any discrapancies please contact 'Shobhit Mathur (smathur3@in.ibm.com)'.</h10></center></p>"
Add-Content $ReportFile2 "</body>"
#---------------------------------#
# Javascript to Activate the Tabs #
#---------------------------------#
Add-Content $ReportFile2 "<script type='text/javascript'>"
Add-Content $ReportFile2 "// Wrapped in a function so as to not pollute the global scope."
Add-Content $ReportFile2 "var activatables = (function () {"
Add-Content $ReportFile2 "// The CSS classes to use for active/inactive elements."
Add-Content $ReportFile2 "var activeClass = 'active';"
Add-Content $ReportFile2 "var inactiveClass = 'inactive';"
Add-Content $ReportFile2 "  "
Add-Content $ReportFile2 "var anchors = {}, activates = {};"
Add-Content $ReportFile2 "var regex = /#([A-Za-z][A-Za-z0-9:._-]*)$/;"
Add-Content $ReportFile2 "  "
Add-Content $ReportFile2 "// Find all anchors (<a href='#something'>.)"
Add-Content $ReportFile2 "var temp = document.getElementsByTagName('a');"
Add-Content $ReportFile2 "for (var i = 0; i < temp.length; i++) {"
Add-Content $ReportFile2 "     var a = temp[i];"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Make sure the anchor isn't linking to another page."
Add-Content $ReportFile2 " if ((a.pathname != location.pathname &&"
Add-Content $ReportFile2 " '/' + a.pathname != location.pathname) ||"
Add-Content $ReportFile2 " a.search != location.search) continue;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Make sure the anchor has a hash part."
Add-Content $ReportFile2 " var match = regex.exec(a.href);"
Add-Content $ReportFile2 " if (!match) continue;"
Add-Content $ReportFile2 " var id = match[1];"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Add the anchor to a lookup table."
Add-Content $ReportFile2 " if (id in anchors)"
Add-Content $ReportFile2 " anchors[id].push(a);"
Add-Content $ReportFile2 " else"
Add-Content $ReportFile2 " anchors[id] = [a];"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "// Adds/removes the active/inactive CSS classes depending on whether the"
Add-Content $ReportFile2 "// element is active or not."
Add-Content $ReportFile2 "function setClass(elem, active) {"
Add-Content $ReportFile2 " var classes = elem.className.split(/\s+/);"
Add-Content $ReportFile2 " var cls = active ? activeClass : inactiveClass, found = false;"
Add-Content $ReportFile2 " for (var i = 0; i < classes.length; i++) {"
Add-Content $ReportFile2 " if (classes[i] == activeClass || classes[i] == inactiveClass) {"
Add-Content $ReportFile2 " if (!found) {"
Add-Content $ReportFile2 " classes[i] = cls;"
Add-Content $ReportFile2 " found = true;"
Add-Content $ReportFile2 " } else {"
Add-Content $ReportFile2 " delete classes[i--];"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " if (!found) classes.push(cls);"
Add-Content $ReportFile2 " elem.className = classes.join(' ');"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "// Functions for managing the hash."
Add-Content $ReportFile2 "function getParams() {"
Add-Content $ReportFile2 " var hash = location.hash || '#';"
Add-Content $ReportFile2 " var parts = hash.substring(1).split('&');"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " var params = {};"
Add-Content $ReportFile2 " for (var i = 0; i < parts.length; i++) {"
Add-Content $ReportFile2 " var nv = parts[i].split('=');"
Add-Content $ReportFile2 " if (!nv[0]) continue;"
Add-Content $ReportFile2 " params[nv[0]] = nv[1] || null;"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " return params;"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "function setParams(params) {"
Add-Content $ReportFile2 " var parts = [];"
Add-Content $ReportFile2 " for (var name in params) {"
Add-Content $ReportFile2 " // One of the following two lines of code must be commented out. Use the"
Add-Content $ReportFile2 " // first to keep empty values in the hash query string; use the second"
Add-Content $ReportFile2 " // to remove them."
Add-Content $ReportFile2 " //parts.push(params[name] ? name + '=' + params[name] : name);"
Add-Content $ReportFile2 " if (params[name]) parts.push(name + '=' + params[name]);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " location.hash = knownHash = '#' + parts.join('&');"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "// Looks for changes to the hash."
Add-Content $ReportFile2 "var knownHash = location.hash;"
Add-Content $ReportFile2 "function pollHash() {"
Add-Content $ReportFile2 " var hash = location.hash;"
Add-Content $ReportFile2 " if (hash != knownHash) {"
Add-Content $ReportFile2 " var params = getParams();"
Add-Content $ReportFile2 " for (var name in params) {"
Add-Content $ReportFile2 " if (!(name in activates)) continue;"
Add-Content $ReportFile2 " activates[name](params[name]);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " knownHash = hash;"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "setInterval(pollHash, 250);"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "function getParam(name) {"
Add-Content $ReportFile2 " var params = getParams();"
Add-Content $ReportFile2 " return params[name];"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "function setParam(name, value) {"
Add-Content $ReportFile2 " var params = getParams();"
Add-Content $ReportFile2 " params[name] = value;"
Add-Content $ReportFile2 " setParams(params);"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "// If the hash is currently set to something that looks like a single id,"
Add-Content $ReportFile2 "// automatically activate any elements with that id."
Add-Content $ReportFile2 "var initialId = null;"
Add-Content $ReportFile2 "var match = regex.exec(knownHash);"
Add-Content $ReportFile2 "if (match) {"
Add-Content $ReportFile2 " initialId = match[1];"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "// Takes an array of either element IDs or a hash with the element ID as the key"
Add-Content $ReportFile2 "// and an array of sub-element IDs as the value."
Add-Content $ReportFile2 "// When activating these sub-elements, all parent elements will also be"
Add-Content $ReportFile2 "// activated in the process."
Add-Content $ReportFile2 "function makeActivatable(paramName, activatables) {"
Add-Content $ReportFile2 " var all = {}, first = initialId;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Activates all elements for a specific id (and inactivates the others.)"
Add-Content $ReportFile2 " function activate(id) {"
Add-Content $ReportFile2 " if (!(id in all)) return false;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " for (var cur in all) {"
Add-Content $ReportFile2 " if (cur == id) continue;"
Add-Content $ReportFile2 " for (var i = 0; i < all[cur].length; i++) {"
Add-Content $ReportFile2 " setClass(all[cur][i], false);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " for (var i = 0; i < all[id].length; i++) {"
Add-Content $ReportFile2 " setClass(all[id][i], true);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " setParam(paramName, id);"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " return true;"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " activates[paramName] = activate;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " function attach(item, basePath) {"
Add-Content $ReportFile2 " if (item instanceof Array) {"
Add-Content $ReportFile2 " for (var i = 0; i < item.length; i++) {"
Add-Content $ReportFile2 " attach(item[i], basePath);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " } else if (typeof item == 'object') {"
Add-Content $ReportFile2 " for (var p in item) {"
Add-Content $ReportFile2 " var path = attach(p, basePath);"
Add-Content $ReportFile2 " attach(item[p], path);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " } else if (typeof item == 'string') {"
Add-Content $ReportFile2 " var path = basePath ? basePath.slice(0) : [];"
Add-Content $ReportFile2 " var e = document.getElementById(item);"
Add-Content $ReportFile2 " if (e)"
Add-Content $ReportFile2 " path.push(e);"
Add-Content $ReportFile2 " else "
Add-Content $ReportFile2 " return;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " if (!first) first = item;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Store the elements in a lookup table."
Add-Content $ReportFile2 " all[item] = path;"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Attach a function that will activate the appropriate element"
Add-Content $ReportFile2 " // to all anchors."
Add-Content $ReportFile2 " if (item in anchors) {"
Add-Content $ReportFile2 " // Create a function that will call the 'activate' function with"
Add-Content $ReportFile2 " // the proper parameters. It will be used as the event callback."
Add-Content $ReportFile2 " var func = (function (id) {"
Add-Content $ReportFile2 " return function (e) {"
Add-Content $ReportFile2 " activate(id);"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " if (!e) e = window.event;"
Add-Content $ReportFile2 " if (e.preventDefault) e.preventDefault();"
Add-Content $ReportFile2 " e.returnValue = false;"
Add-Content $ReportFile2 " return false;"
Add-Content $ReportFile2 " };"
Add-Content $ReportFile2 " })(item);"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " for (var i = 0; i < anchors[item].length; i++) {"
Add-Content $ReportFile2 " var a = anchors[item][i];"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " if (a.addEventListener) {"
Add-Content $ReportFile2 " a.addEventListener('click', func, false);"
Add-Content $ReportFile2 " } else if (a.attachEvent) {"
Add-Content $ReportFile2 " a.attachEvent('onclick', func);"
Add-Content $ReportFile2 " } else {"
Add-Content $ReportFile2 " throw 'Unsupported event model.';"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " all[item].push(a);"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " return path;"
Add-Content $ReportFile2 " } else {"
Add-Content $ReportFile2 " throw 'Unexpected type.';"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " return basePath;"
Add-Content $ReportFile2 " }"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " attach(activatables);"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 " // Activate an element."
Add-Content $ReportFile2 " if (first) activate(getParam(paramName)) || activate(first);"
Add-Content $ReportFile2 "}"
Add-Content $ReportFile2 "   "
Add-Content $ReportFile2 "return makeActivatable;"
Add-Content $ReportFile2 "})();"
Add-Content $ReportFile2 "   "
#Add-Content $ReportFile2 "activatables('page', ['page-1', 'page-2','page-3','page-4','page-5','page-6']);"
Add-Content $ReportFile2 "activatables('page', ['page-1', 'page-2','page-3','page-4','page-6']);"
Add-Content $ReportFile2 "</script>"
Add-Content $ReportFile2 "</html>"
##########################################################################
 $From = "Sho ScriptBox <shobhit.mathur@westpac.com.au>"
$To = "ramakts1@in.ibm.com" , "gupadkan@in.ibm.com" , "jeffpai@nz1.ibm.com" , "shobhit.mathur@westpac.com.au" 
$Cc = "demishal@in.ibm.com" , "anooptd3@in.ibm.com" , "emichael@in.ibm.com" ,"kavitmut@in.ibm.com", "kupramar@in.ibm.com" , "shmuthap@in.ibm.com" ,`
 "sundkada@in.ibm.com" , "turmishr@in.ibm.com" , "msuhail0@in.ibm.com" , "mohbeedi@in.ibm.com" , "anandkempanna@in.ibm.com" , "vijas113@in.ibm.com" ,"prasabad@in.ibm.com",`
  "supayyan@in.ibm.com" , "kkothuri@in.ibm.com" , "smathur3@in.ibm.com" , "hsjukri@au1.ibm.com",`
  "wlinuxin@in.ibm.com" ,  "pramach9@in.ibm.com" ,"aswini.sista@in.ibm.com"`
   ,"gupadkan@in.ibm.com","lohit.parappa@in.ibm.com"
#$To = "shobhit.mathur@westpac.com.au" 
#$Cc = "smathur3@in.ibm.com"  
$BCC = "smathur3@in.ibm.com" 
$Subject = "Westpac vCenters & ESXi Report"
$Body1 = "<p>Dear Team, <br><br>
Attached is the DHC Report for today.</p>"
$Body2 = "<p><br>
This is script generated report, hence for any discrepancies please contact 'Shobhit Mathur (smathur3@in.ibm.com)'.<br><br>
Best Regards<br>
Sho</p><br>" 
$HTMLBody = $Body1 + $Body2 
$SMTPServer = "appsmtp.thewestpacgroup.com.au"
$SMTPPort = "25"
Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer  -Attachments $ReportFile2
##########################################################################

No comments:

Post a Comment