SSH

SSH

###########################vCenter Server SSH Report #################################
############################## Created By Shobhit Mathur ###################################
############################## MAR - Modify As Required ####################################

$VIServers= "xxx"   ###MAR###
$reportFile = Get-Date -UFormat "E:\Sho\Reports\$VIServers-Snapshot_Report-%Y-%b-%d @ %I-%M%p.html"
$today = get-Date

$Sho=@"
<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: #fffc00;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@

If (-not (Get-PSSnapin VMware.VimAutomation.Core))
{  Try { Add-PSSnapin VMware.VimAutomation.Core -ErrorAction Stop }
   Catch { Write-Host "Unable to load PowerCLI, is it installed?" -ForegroundColor Red; Break }
}
 Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
foreach($viserver in $VIServers)
{
Connect-VIServer $VIServers -User xxx -Password xxx ###MAR###
}

$Sho += Get-VMHost | Get-VMHostService | ?{"TSM","TSM-SSH" -contains $_.Key -and $_.Running} |select VMHost, Label, Running | ConvertTo-Html -Fragment


$From = "xxx"   ###MAR###
$To = "xxx"   ###MAR###
$CC = "xxx"   ###MAR###
$BCC = "xxx"   ###MAR###
$Subject = "SSH Report of $VIServers"
$Body = "<p>Dear Team, <br><br>

Here is the SSH Report of $VIServers as on $today.<br><br>

</p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd

$Body1 = "<p><h4> If the report is blank then there are no ESXi hosts with SSH enabled</h4><br>

This is script generated report, hence for any discrapancies please contact 'xxx' ###MAR###.<br><br>

Best Regards<br>
Sho</p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd


$HTMLBody = $Body + $Sho + $Body1
$SMTPServer = "xxx"  ###MAR###
$SMTPPort = "25" ###MAR###
Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer

Disconnect-VIServer $VIServers -Force -Confirm:$false

No comments:

Post a Comment