Exchange Server-Sicherungsbericht PowerShell

In diesem Artikel werde ich Ihnen das Backup-Berichtsskript vorstellen, das ich für meine eigene Umgebung verwendet und bearbeitet habe, und wir werden darüber sprechen, wie es funktioniert.

Zunächst müssen Sie die Variablen in den Zeilen 12 bis 18 entsprechend Ihrer eigenen Umgebung bearbeiten. Die relevanten Variablen sind Mailserver, von, bis usw. Es umfasst Parameter wie.

# 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"

Anschließend überprüft das Skript den Ordner „C:Backup Report“ und erstellt den Ordner, wenn der entsprechende Ordner nicht vorhanden ist. Sie können den Ordnererstellungsprozess als Ausgabe auf dem PowerShell-Bildschirm sehen. Anschließend werden Sie mit dem Befehl „get-credential“ nach Ihren From-Kontoinformationen gefragt und diese Kontoinformationen im als .xml erstellten Ordner „Sicherungsbericht“ gespeichert. Falls das Skript erneut ausgeführt wird, wird eine erneute Überprüfung durchgeführt und die Kontoinformationen werden importiert.

1 Bild
Image
# 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

Das Exchange Server-Sicherungsberichtsskript sendet E-Mails im HTML-Format und zeigt die Datenbankgröße, die Anzahl der Postfächer, den Status „Gemountet/Nicht gemountet“, DAG-Informationen und den Backup-Typ für die relevante Datenbank an.

2 Bild
3 Bild
<#
=============================================================================================
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

Ähnliche Artikel – Exchange Server Backup Report PowerShell

Kommentar