Dans cet article, je partagerai avec vous le script de rapport de sauvegarde que j'ai utilisé et modifié pour mon propre environnement et nous parlerons de son fonctionnement.
Tout d'abord, vous devez modifier les variables des lignes 12 à 18 en fonction de votre propre environnement, les variables pertinentes sont le serveur de messagerie, de, à, etc. Il comprend des paramètres tels que.
# Mail, Subject and File
$From = "[email protected]"
$To = "[email protected]"
$SMTPServer = "[email protected]"
$Port = 587
$Priority = "High"
$Subject = "Exchange Server Backup Report"
$CredentialFile = "C:Backup Reportcredentials.backup"
Ensuite, le script vérifie le dossier C:Backup Report et crée le dossier si le dossier correspondant n'existe pas. Vous pouvez voir le processus de création de dossier comme sortie sur l'écran PowerShell. Ensuite, il vous demande les informations de votre compte From avec la commande get-credential et enregistre ces informations de compte dans le dossier Rapport de sauvegarde créé au format .xml. Si le script s'exécute à nouveau, une nouvelle vérification est effectuée et les informations du compte sont importées.


# Backup Report Folder
if (!(Test-Path "C:Backup Report")) {
New-Item -ItemType Directory -Path "C:Backup Report"
}
# Credential Check and Save
if (!(Test-Path $CredentialFile)) {
Get-Credential -Message "Lütfen $From hesabı ile hesap bilgilerini doğrulayın."| Export-Clixml -Path $CredentialFile
}
$Credential = Import-Clixml -Path $CredentialFile
Le script de rapport de sauvegarde d'Exchange Server envoie du courrier au format HTML, affiche la taille de la base de données, le nombre de boîtes aux lettres, l'état monté/démonté, les informations DAG et le type de sauvegarde pour la base de données concernée.


<#
=============================================================================================
Name = Cengiz YILMAZ
Microsoft Certified Trainer (MCT)
Date = 23.03.2023
www.cengizyilmaz.net
www.cozumpark.com/author/cengizyilmaz
============================================================================================
#>
# Mail, Subject and File
$From = "[email protected]"
$To = "[email protected]"
$SMTPServer = "[email protected]"
$Port = 587
$Priority = "High"
$Subject = "Exchange Server Backup Report"
$CredentialFile = "C:Backup Reportcredentials.backup"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# Backup Report Folder
if (!(Test-Path "C:Backup Report")) {
New-Item -ItemType Directory -Path "C:Backup Report"
}
# Credential Check and Save
if (!(Test-Path $CredentialFile)) {
Get-Credential -Message "Lütfen $From hesabı ile hesap bilgilerini doğrulayın."| Export-Clixml -Path $CredentialFile
}
$Credential = Import-Clixml -Path $CredentialFile
# Database Info
$Databases = Get-MailboxDatabase -Status | Select Name, Server, Mounted, LastFullBackup, LastIncrementalBackup, DatabaseSize, MasterType, MasterServerOrAvailabilityGroup, @{Name='Mailboxes';Expression={(Get-Mailbox -Database $_.Name).Count}}
# Number of unsupported databases
$UnbackedUpCount = ($Databases | Where-Object {-not $_.LastFullBackup -and -not $_.LastIncrementalBackup}).Count
$BackedUpCount = ($Databases.Count) - $UnbackedUpCount
#
$AllDbCount = ($Databases).Count
$BackedUpCount = ($Databases | Where-Object { $_.LastFullBackup }).Count
$UnbackedUpCount = $AllDbCount - $BackedUpCount
# Creating an HTML report
$HTMLReport = @"
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 15px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.fail {
color: red;
background-color: #fdd;
}
.success {
background-color: #dfd;
}
.incremental {
background-color: #ffea7f;
}
</style>
</head>
<body>
<h2>Exchange Server Backup Report</h2>
<p>Toplamda $AllDbCount DB bulunmaktadir. Bunlardan $BackedUpCount tanesi yedeklenmistir ve $UnbackedUpCount tanesi yedeklenmemistir.</p>
<h3>Yedeklenmemis Databases</h3>
<table>
<tr>
<th>Name</th>
<th>Server</th>
<th>DAG</th>
<th>Health</th>
<th>Backup Type</th>
<th>Backup Time</th>
<th>Database Size</th>
<th>Mailboxes</th>
</tr>
$($Databases | Where-Object {-not $_.LastFullBackup -and -not $_.LastIncrementalBackup} | ForEach-Object {
$backupType = "<td class='fail'>Fail</td>"
$backupTime = 'N/A'
$health = "$($_.Mounted) / $($_.MasterType)"
@"
<tr>
<td>$($_.Name)</td>
<td>$($_.Server)</td>
<td>$($_.MasterServerOrAvailabilityGroup)</td>
<td>$health</td>
$backupType
<td>$backupTime</td>
<td>$($_.DatabaseSize)</td>
<td>$($_.Mailboxes)</td>
</tr>
"@})
</table>
<h3>Yedeklenmis Databases</h3>
<table>
<tr>
<th>Name</th>
<th>Server</th>
<th>DAG</th>
<th>Health</th>
<th>Backup Type</th>
<th>Backup Time</th>
<th>Database Size</th>
<th>Mailboxes</th>
</tr>
$($Databases | Where-Object { $_.LastFullBackup -or $_.LastIncrementalBackup } | ForEach-Object {
$backupType = if ($_.LastFullBackup) { "<td class='success'>Full</td>" } elseif ($_.LastIncrementalBackup) { "<td class='incremental'>Incremental</td>" } else { "<td class='fail'>Fail</td>" }
$backupTime = if ($_.LastFullBackup) { $_.LastFullBackup } elseif ($_.LastIncrementalBackup) { $_.LastIncrementalBackup } else { 'N/A' }
$health = "$($_.Mounted) / $($_.MasterType)"
@"
<tr>
<td>$($_.Name)</td>
<td>$($_.Server)</td>
<td>$($_.MasterServerOrAvailabilityGroup)</td>
<td>$health</td>
$backupType
<td>$backupTime</td>
<td>$($_.DatabaseSize)</td>
<td>$($_.Mailboxes)</td>
</tr>
"@})
</table>
</body>
</html>
"@
# Sending the report by e-mail
$MessageParameters = @{
From = $From
To = $To
Subject = $Subject
Priority = $Priority
Body = $HTMLReport
BodyAsHtml = $true
SmtpServer = $SMTPServer
Port = $Port
Credential = $Credential
}
Send-MailMessage @MessageParameters