나는 그것을 실행할 때 서버 상태 세부 정보와 함께 이메일을 보내고에 대한 정보를 인쇄하는 스크립트를 powershell에 가지고 있습니다. 화면on powershell 스크립트를 공유 폴더에 텍스트 파일로 저장하고 화면에 인쇄하고 이메일을 보내는 방법
내가 이메일을 보내는 것과 같은 aswell 그리고 그것은 또한 메모장에 결과를 저장하고 공유 드라이브의 폴더에 저장 화면의 정보를 인쇄 스크립트에 추가 지금 찾고나는 새로운 오전 Powershell에서 그렇게하는 방법을 모르겠다.
감사
OS를 필요한 경우 내 코드를 추가 할 수
코드 PowerShell에서 파일을 작성하는 많은 방법이있다
$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
코드를 추가하십시오. 질문에 대답하는 것이 더 도움이 될 것입니다. – Persistent13