Ich habe ein Skript auf Powershell, dass wenn es ausgeführt wird, senden Sie eine E-Mail mit Serverstatusdetails und druckt auch die Informationen aufauf Powershell wie Skript als eine Textdatei in einem freigegebenen Ordner sowie Drucken auf dem Bildschirm speichern und E-Mail senden
Bildschirmich jetzt bin auf der Suche, um das Skript hinzuzufügen, das als das Senden der E-Mail-aswell und druckt die Informationen auf dem Bildschirm speichert sie auch die Ergebnisse auf Notizblock und speichert sie in einem Ordner auf dem freigegebenen Laufwerk
ich bin neu Powershell so nicht sicher, wie ich das mache. Ich kann meinen Code hinzufügen, wenn nötig
dank
os
der Code
$DirectoryPath = Split-Path $MyInvocation.MyCommand.Path
$ConfigurationPath = $DirectoryPath + '\Config file.xml'
Function FormatCell
{
param($cellValue)
$cell = "<td>" + $cellValue + "</td>"
return $cell
}
Function Getservicechecker
{
[xml]$ConfigFile = Get-Content $ConfigurationPath
$Servers = $ConfigFile.SelectNodes('/Configs/Servers/Server')
$ServString = "<tr><th>Server</th><th>IP Address</th><th>Process</th> <th>Status</th></tr>"
foreach($Server in $Servers)
{
[string]$serverName = $Server.ServerName
$OutputText += "Server: " + $serverName + $NL
$Process = $Server.ProcessesToMonitor
foreach($Processtomonitor in $Process.ChildNodes)
{
$ServString += "<tr>"
$ServString += FormatCell -cellValue $serverName
$ipaddress = Test-Connection $serverName -count 1 | select Ipv4Address
$ipAddressValue = $ipaddress.IPV4Address.IPAddressToString
$servString += FormatCell -cellValue $ipAddressValue
[string]$processName = $Processtomonitor.InnerText
$servicestatus = Get-service -ComputerName $serverName -Name $processName | select status
$ServString += FormatCell -cellValue $processName
$FormatedStatus = 'status'
[string]$statusString = -join $servicestatus
$statusString = $statusString.Remove(0,"@{Status=".Length)
$statusString = $statusString.Remove($statusString.IndexOf("}"))
$FormatedServiceStatus = FormatCell -cellValue $servicestatus
If ($FormatedServiceStatus –eq “<td>@{Status=Running}</td>”)
{
$Formatedstatus = 'Running'
}
elseif ($FormatedServiceStatus –eq “<td>@{Status=Stopped}</td>”)
{
$Formatedstatus = "<p style='color:red'>Service stopped investigation required</p>"
}
else
{
$FormatedStatus = "$servicestatus potential investigation"
}
Write-host "server: $serverName `t ipaddress: $ipAddressValue `t process: $processName `t status: $statusString"
$ServString += FormatCell -cellValue $Formatedstatus
$ServString += "</tr>"
}
}
return "<table class=""gridtable"">" + $ServString + "</table>"
}
function SendMail
{
param($bodyText, $subject)
$SmtpServer = "164.134.84.81"
$emailMessage = New-Object System.Net.Mail.MailMessage
$fromaddress = "[email protected]"
$recipients = ("[email protected]")
$Subject = "BOXI Servers Report for " +$dateTimeOfServiceCheck
$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE>"
$body += "<style type=""text/css"">table.gridtable {font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #666666;border-collapse: collapse;}"
$body += "table.gridtable th {border-width: 1px;padding: 8px;border-style: solid;border-color: #666666; background-color: #dedede;}"
$body += "table.gridtable td {border-width: 1px;padding: 8px;border-style: solid;border-color: #666666; background-color: #ffffff;}</style></HEAD>"
$body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: TAHOMA; color: #000000"">"
$body += $bodyText
Send-MailMessage -to $recipients -subject $subject -bodyashtml -body $body - from $fromAddress -SmtpServer $smtpServer -Port 25
}
function main
{
$dateTimeOfServiceCheck = Get-Date -Format F
$outputText = "Service Checker :" + $dateTimeOfServiceCheck
$emailBody = "<h3>"+$outputText +"</h3>" #take out if dont want datetime above table
$emailBody += Getservicechecker
SendMail $emailBody "BOXI Servers Report for" +$dateTimeOfServiceCheck
}
main
öffnen. Bitte fügen Sie Ihren Code hinzu; es wird einfacher sein, die Frage in der Weise zu beantworten, die Ihnen dabei helfen wird. – Persistent13