1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#-------------------------------- #| Get Data and Set Variables #-------------------------------- $date = (Get-Date).ToString() $smtpServer = "smtphost" $smtpTo = "epic@domain.com" $smtpFrom = "from@domain.com" $messageSubject = "Daily Report - $date" $OutputFile = "c:\temp\Output.htm" $ServerList = Get-Content "computers.txt" #-------------------------------- #| Run Check Computer Names and Generates Report #-------------------------------- $Result = @() Foreach($ServerName in $ServerList) { $pingStatus = Get-WmiObject -Query "Select * from win32_PingStatus where Address='$ServerName'" $Result += New-Object PSObject -Property @{ ServerName = $ServerName IPV4Address = $pingStatus.IPV4Address Status = test-Connection -ComputerName $ServerName -Count 2 -Quiet } } if($Result -ne $null) { $HTML = '<style type="text/css"> #Header{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;width:50%;border-collapse:collapse;} #Header td, #Header th {font-size:14px;border:1px solid #000000;} #Header th {font-size:14px;text-align:left;padding-top:5px;padding-bottom:1px;background-color:#000000;color:#fff;} #Header tr.alt td {color:#000;background-color:#EAF2D3;} </Style>' $HTML += "<HTML><BODY><Table border=1 cellpadding=0 cellspacing=0 id=Header> <TR> <TH><B>ID Scanner</B></TH> <TH><B>IP Address</B></TD> <TH><B>Status</B></TH> </TR>" Foreach($Entry in $Result) { if($Entry.Status -ne "true") { $HTML += "<TR bgColor=Red> <TD><B>$($Entry.ServerName)</B></TD> <TD>$($Entry.IPV4Address)</TD> <TD>Offline</TD> </TR>" } else { $HTML += "<TR bgColor=Green> <TD><B>$($Entry.ServerName)</B></TD> <TD>$($Entry.IPV4Address)</TD> <TD>Online</TD> </TR>" } } $HTML += "</Table></BODY></HTML>" $HTML | Out-File $OutputFile #-------------------------------- #| Sends Report #-------------------------------- Send-MailMessage -From $smtpFrom -To $smtpTo -Subject $messagesubject -Body $HTML -BodyAsHtml -SmtpServer $smtpServer } |