commit 0b799aeb554c13004402493e6b89f033f410c3ae Author: smolkik_adm Date: Fri Jun 26 08:15:33 2026 +0000 Добавить NotifyOfDisabledJobs.ps1 diff --git a/NotifyOfDisabledJobs.ps1 b/NotifyOfDisabledJobs.ps1 new file mode 100644 index 0000000..d9a2266 --- /dev/null +++ b/NotifyOfDisabledJobs.ps1 @@ -0,0 +1,93 @@ +<# +************************************************************************************ +PowerShell script that checks for disabled jobs and sends an e-mail containing the list +of disabled Veeam jobs. +************************************************************************************ +#> +Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue +$ScriptDir = 'C:\setup\script' +$JobExclusionFilterFile = "$ScriptDir\NotifyOfDisabledJobs_EXCLUSIONS.IN" +$MailTo = @( + "KrapivinAA@nornik.ru" + "RudenkoVV@nornik.ru" + "smolinmv@nornik.ru" +) +$MailFrom = "smolinmv@nornik.ru" +$MailSubject = "ALERT: Veeam jobs disabled" +$SMTPServer = "" +$SMTPPort = 587 +$SMTPUser = "smolinmv@nornik.ru" +$SMTPPass = "" +$SMTPUseSSL = $true +# Использовать TLS 1.2 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$DisabledJobs = Get-VBRJob | Where-Object { + $_.Info.IsScheduleEnabled -eq $false +} +if ($DisabledJobs) { + if ((Test-Path $JobExclusionFilterFile) -and + (-not [string]::IsNullOrWhiteSpace((Get-Content $JobExclusionFilterFile)))) { + $JobsToExclude = Get-Content $JobExclusionFilterFile + $DisabledJobsWithExclusions = $DisabledJobs.Name | + Select-String -Pattern $JobsToExclude -NotMatch | + Out-String + $JobsToExclude = $JobsToExclude | Out-String + $FinalReport = $DisabledJobsWithExclusions + } + else { + Write-Host "No job exclusion filter set" + $JobsToExclude = "None" + $FinalReport = $DisabledJobs.Name | Out-String + } + $EmailBody = @" +Пожалуйста, проверьте следующие отключенные задания Veeam и повторно включите их, повторно включите или удалите расписание, либо добавьте их в файл списка исключений.: +$FinalReport +Задания, имеющие следующие поисковые фильтры, исключаются из отчета.: +$JobsToExclude +"@ + Write-Host $EmailBody + $SMTPCredential = New-Object System.Management.Automation.PSCredential( + $SMTPUser, + (ConvertTo-SecureString $SMTPPass -AsPlainText -Force) + ) + # Отключаем проверку сертификата + [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { + param($sender, $certificate, $chain, $sslPolicyErrors) + return $true + } + try { + $mail = New-Object System.Net.Mail.MailMessage + $mail.From = $MailFrom + foreach ($Recipient in $MailTo) { + $mail.To.Add($Recipient) +} + $mail.Subject = $MailSubject + $mail.Body = $EmailBody + $mail.IsBodyHtml = $false + $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort) + $smtp.EnableSsl = $SMTPUseSSL + $smtp.Credentials = $SMTPCredential + $smtp.Send($mail) + Write-Host "E-mail sent successfully." -ForegroundColor Green + } + catch { + Write-Host "SMTP Error:" -ForegroundColor Red + Write-Host $_.Exception.Message -ForegroundColor Red + if ($_.Exception.InnerException) { + Write-Host $_.Exception.InnerException.Message -ForegroundColor Yellow + } + } + finally { + # Возвращаем стандартную проверку сертификатов + [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null + if ($mail) { + $mail.Dispose() + } + if ($smtp) { + $smtp.Dispose() + } + } +} +else { + Write-Host "No disabled jobs" +}