나는 최근에 정의 된 횟수로 서비스를 다시 시작하려고 시도하고 결론적으로 전자 메일 알림을 보내는 powershell 스크립트를 실행하는 복구 옵션을 구현했으며 최근 관련 로그가있는 txt 파일도 첨부합니다.
프로그램 : PowerShell.exe의
**하지 C를 다음과 같이
여러 번 시도 후
(그리고 내가 본 다른 모든 것들에도 불구하고) 서비스에서 복구 탭에서 필드의 구성은 \ 윈도우 \ System32 \ WindowsPowerShell \ v1.0 \ Powershell.exe
명령 줄 매개 변수 : -command "& {SomePath \ YourScript.ps1 '$ args [0]'$ args [1] '} "
예 : -command"& {C : \ PowershellScripts \ ServicesRecovery.ps 1 '서비스 이름'} "
** $ args는 스크립트에 전달되는 매개 변수입니다. 필수 사항은 아닙니다.
cd $PSScriptRoot
$n = $args[0]
function CreateLogFile {
$events = Get-EventLog -LogName Application -Source SomeSource -Newest 40
if (!(Test-Path "c:\temp")) {
New-Item -Path "c:\temp" -Type directory}
if (!(Test-Path "c:\temp\ServicesLogs.txt")) {
New-Item -Path "c:\temp" -Type File -Name "ServicesLogs.txt"}
$events | Out-File -width 600 c:\temp\ServicesLogs.txt
}
function SendEmail {
$EmailServer = "SMTP Server"
$ToAddress = "[email protected]"
$FromAddress = "[email protected]"
CreateLogFile
$Retrycount = $Retrycount + 1
send-mailmessage -SmtpServer $EmailServer -Priority High -To $ToAddress -From $FromAddress -Subject "$n Service failure" `
-Body "The $n service on server $env:COMPUTERNAME has stopped and was unable to be restarted after $Retrycount attempts." -Attachments c:\temp\ServicesLogs.txt
Remove-Item "c:\temp\ServicesLogs.txt"
}
function SendEmailFail {
$EmailServer = "SMTP Server"
$ToAddress = "[email protected]"
$FromAddress = "[email protected]"
CreateLogFile
$Retrycount = $Retrycount + 1
send-mailmessage -SmtpServer $EmailServer -Priority High -To $ToAddress -From $FromAddress -Subject "$n Service Restarted" `
-Body "The $n service on server $env:COMPUTERNAME stopped and was successfully restarted after $Retrycount attempts. The relevant system logs are attached." -Attachments c:\temp\ServicesLogs.txt
Remove-Item "c:\temp\ServicesLogs.txt"
}
function StartService {
$Stoploop = $false
do {
if ($Retrycount -gt 3){
$Stoploop = $true
SendEmail
Break
}
$i = Get-WmiObject win32_service | ?{$_.Name -imatch $n} | select Name, State, StartMode
if ($i.State -ne "Running" -and $i.StartMode -ne "Disabled") {
sc.exe start $n
Start-Sleep -Seconds 35
$i = Get-WmiObject win32_service | ?{$_.Name -imatch $n} | select State
if ($i.state -eq "Running"){
$Stoploop = $true
SendEmailFail}
else {$Retrycount = $Retrycount + 1}
}
}
While ($Stoploop -eq $false)
}
[int]$Retrycount = "0"
StartService
: 여기
는 파워 쉘 스크립트입니다