Import-Module ActiveDirectory
$enc = New-Object System.Text.utf8encoding
$servidores=Get-ADComputer -Filter {(OperatingSystem -like "*Server*")} -Properties OperatingSystem | Sort-Object Name
foreach ($servidor in $servidores) {
$dnsservername=$servidor.name+".midominio.local"
if (Test-Connection -ComputerName $dnsservername -Count 1 -Quiet) {
$resptime=Test-Connection -ComputerName $dnsservername -Count 1
$tabla1 += "<tr><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>"+$resptime.ResponseTime+"</td></tr>"
} else {
$tabla1 += "<tr BGCOLOR='#DF0101'><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>No responde ping</td></tr>"
}
#$tabla1 += "<tr><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>"+$servidor.operatingSystem+"</td></tr>"
#Get-WmiObject win32_operatingsystem -ComputerName $servidor.Name | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}
$body = @"
<center><h1><b>Informe Servidores V1</h1><br></center>
<table border="1">
<tr><td><b>Nombre del Servidor</td><td><b>Sistema operativo</td><td><b>Respuesta Ping</td></tr>
$tabla1
</table>
<br>
Desde ya es un placer chequear esta característica, para ayudarle a brindar un mejor servicio IT.<br>
<br>
Saludos cordiales,<br>
"@
send-mailmessage -to mibuzon@midominio.local -from "Mi nombre <mibuzon@midominio.local>" -Subject "Reporte Servidores V1" -body $body -smtpserver miservidordecorreo -Encoding $enc -BodyAsHtml
$enc = New-Object System.Text.utf8encoding
$servidores=Get-ADComputer -Filter {(OperatingSystem -like "*Server*")} -Properties OperatingSystem | Sort-Object Name
foreach ($servidor in $servidores) {
$dnsservername=$servidor.name+".midominio.local"
if (Test-Connection -ComputerName $dnsservername -Count 1 -Quiet) {
$resptime=Test-Connection -ComputerName $dnsservername -Count 1
$tabla1 += "<tr><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>"+$resptime.ResponseTime+"</td></tr>"
} else {
$tabla1 += "<tr BGCOLOR='#DF0101'><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>No responde ping</td></tr>"
}
#$tabla1 += "<tr><td>"+$servidor.name+"</td><td>"+$servidor.operatingSystem+"</td><td>"+$servidor.operatingSystem+"</td></tr>"
#Get-WmiObject win32_operatingsystem -ComputerName $servidor.Name | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}
$body = @"
<center><h1><b>Informe Servidores V1</h1><br></center>
<table border="1">
<tr><td><b>Nombre del Servidor</td><td><b>Sistema operativo</td><td><b>Respuesta Ping</td></tr>
$tabla1
</table>
<br>
Desde ya es un placer chequear esta característica, para ayudarle a brindar un mejor servicio IT.<br>
<br>
Saludos cordiales,<br>
"@
send-mailmessage -to mibuzon@midominio.local -from "Mi nombre <mibuzon@midominio.local>" -Subject "Reporte Servidores V1" -body $body -smtpserver miservidordecorreo -Encoding $enc -BodyAsHtml