Friday, October 4, 2024
HomePowershellLively Listing Replication Abstract to your Electronic mail or Microsoft Groups

Lively Listing Replication Abstract to your Electronic mail or Microsoft Groups


So, as a part of my superior Lively Listing module referred to as ADEssentials, I wrote a perform that makes use of repadmin to generate outcomes. Then, I exploit PSWriteHTML to course of them and Mailozaurr to ship them to my e mail. This is a how I did it:

$ReplicationSummary = Get-WinADForestReplicationSummary -IncludeStatisticsVariable Statistics

$Physique = EmailBody {
    EmailImage -Supply 'https://evotec.xyz/wp-content/uploads/2021/04/Emblem-evotec-bb.png' -UrlLink '' -AlternativeText 'Emblem' -Width 181 -Heigh 57 -Inline

    EmailText -Textual content "Expensive ", "AD Workforce," -LineBreak
    EmailText -Textual content "Upon reviewing the resuls of replication I've discovered: "
    EmailList {
        EmailListItem -Textual content "Servers with good replication: ", $($Statistics.Good) -Shade Black, SpringGreen -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication failures: ", $($Statistics.Failures) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication delta over 24 hours: ", $($Statistics.DeltaOver24Hours) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication delta over 12 hours: ", $($Statistics.DeltaOver12Hours) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication delta over 6 hours: ", $($Statistics.DeltaOver6Hours) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication delta over 3 hours: ", $($Statistics.DeltaOver3Hours) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Servers with replication delta over 1 hour: ", $($Statistics.DeltaOver1Hours) -Shade Black, Pink -FontWeight regular, daring
        EmailListItem -Textual content "Distinctive replication errors: ", $($Statistics.UniqueErrors.Rely) -Shade Black, Pink -FontWeight regular, daring
    }

    if ($Statistics.UniqueErrors.Rely -gt 0) {
        EmailText -Textual content "Distinctive replication errors:"
        EmailList {
            foreach ($ErrorText in $Statistics.UniqueErrors) {
                EmailListItem -Textual content $ErrorText
            }
        }
    } else {
        EmailText -Textual content "It appears you are doing a fantastic job! Stick with it! 😊" -LineBreak
    }

    EmailText -Textual content "For extra particulars please verify the desk beneath:"

    EmailTable -DataTable $ReplicationSummary {
        EmailTableCondition -Inline -Title "Fail" -HighlightHeaders 'Fails', 'Whole', 'PercentageError' -ComparisonType quantity -Operator gt 0 -BackgroundColor Salmon -FailBackgroundColor SpringGreen
    } -HideFooter

    EmailText -LineBreak
    EmailText -Textual content "Type regards,"
    EmailText -Textual content "Your automation buddy"
}


$EmailSplat = @{
    From           = 'przemyslaw.klys@evotec.pl'
    To             = 'przemyslaw.klys@evotec.pl'
    Physique           = $Physique
    Precedence       = if ($Statistics.Failures -gt 0) { 'Excessive' } else { 'Low' }
    Topic="Replication Outcomes 💖"
    Verbose        = $true
    WhatIf         = $false
    MgGraph        = $true
}

Join-MgGraph
Ship-EmailMessage @EmailSplat

What’s the results of these 50 traces of code?

The Get-WinADForestReplicationSummary perform joins over 100 features obtainable for Lively Listing admins within the ADEssentials module. It is doing the heavy lifting of studying repadmin information and changing it to PowerShell objects. Then, we use the PSWriteHTML EmailBody perform, which permits for the accessible constructing of emails with out understanding HTML and CSS. Lastly, since I needed to ship an e mail with Microsoft Graph, I’ve used Mailozaurr’s superb Ship-EmailMessage to ship an e mail.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments