Src/Private/Get-AbrADSiteReplication.ps1
function Get-AbrADSiteReplication { <# .SYNOPSIS Used by As Built Report to retrieve Microsoft AD Domain Sites Replication information. .DESCRIPTION .NOTES Version: 0.7.5 Author: Jonathan Colon Twitter: @jcolonfzenpr Github: rebelinux .EXAMPLE .LINK #> [CmdletBinding()] param ( [Parameter ( Position = 0, Mandatory)] [string] $Domain ) begin { Write-PscriboMessage "Collecting AD Domain Sites Replication information." } process { Write-PscriboMessage "Collecting AD Domain Sites Replication Summary. (Sites Replication Connection)" $DCs = Invoke-Command -Session $TempPssSession -ScriptBlock {Get-ADDomain -Identity $using:Domain | Select-Object -ExpandProperty ReplicaDirectoryServers} if ($DCs) { Write-PscriboMessage "Discovering Active Directory Sites Replication information on $Domain. (Sites Replication)" try { Section -Style Heading4 'Sites Replication Connection' { Paragraph "The following section provides a summary of the Active Directory Site Replication Connection." BlankLine $OutObj = @() foreach ($DC in $DCs) { if (Test-Connection -ComputerName $DC -Quiet -Count 1) { try { $Replication = Invoke-Command -Session $TempPssSession -ScriptBlock {Get-ADReplicationConnection -Server $using:DC -Properties *} if ($Replication) { Write-PscriboMessage "Collecting Active Directory Sites Replication information on $DC. (Sites Replication Connection)" foreach ($Repl in $Replication) { try { $inObj = [ordered] @{ 'DC Name' = $DC.ToString().ToUpper().Split(".")[0] 'GUID' = $Repl.ObjectGUID 'Description' = ConvertTo-EmptyToFiller $Repl.Description 'Replicate From Directory Server' = ConvertTo-ADObjectName $Repl.ReplicateFromDirectoryServer.Split(",", 2)[1] -Session $TempPssSession -DC $DC 'Replicate To Directory Server' = ConvertTo-ADObjectName $Repl.ReplicateToDirectoryServer -Session $TempPssSession -DC $DC 'Replicated Naming Contexts' = $Repl.ReplicatedNamingContexts 'Transport Protocol' = $Repl.InterSiteTransportProtocol 'AutoGenerated' = ConvertTo-TextYN $Repl.AutoGenerated 'Enabled' = ConvertTo-TextYN $Repl.enabledConnection 'Created' = ($Repl.Created).ToUniversalTime().toString("r") } $OutObj = [pscustomobject]$inobj if ($HealthCheck.Site.Replication) { $OutObj | Where-Object { $_.'Enabled' -ne 'Yes'} | Set-Style -Style Warning -Property 'Enabled' } $TableParams = @{ Name = "Site Replication - $($DC.ToString().ToUpper().Split(".")[0])" List = $true ColumnWidths = 40, 60 } if ($Report.ShowTableCaptions) { $TableParams['Caption'] = "- $($TableParams.Name)" } $OutObj | Table @TableParams if ($HealthCheck.Site.Replication -and ($OutObj | Where-Object { $_.'Enabled' -ne 'Yes'})) { Paragraph "Health Check:" -Italic -Bold -Underline Paragraph "Best Practices: Remove unused Sites replication connections." -Italic -Bold } } catch { Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Site Replication Connection Item)" } } } } catch { Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Site Replication Connection Section)" } } } } } catch { Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Site Replication Connection)" } } try { if ($HealthCheck.Site.Replication) { Write-PscriboMessage "Discovering Active Directory Sites Replication Status on $Domain. (Sites Replication Status)" $DC = Invoke-Command -Session $TempPssSession {Get-ADDomain -Identity $using:Domain | Select-Object -ExpandProperty ReplicaDirectoryServers | Select-Object -First 1} $DCPssSession = New-PSSession $DC -Credential $Credential -Authentication $Options.PSDefaultAuthentication Write-PscriboMessage "Discovered Active Directory Sites Replication Status on $Domain. (Sites Replication Status)" $RepStatus = Invoke-Command -Session $DCPssSession -ScriptBlock {repadmin /showrepl /repsto /csv | ConvertFrom-Csv} if ($RepStatus) { Section -Style Heading4 'Sites Replication Status' { Paragraph "The following section provides a summary of the Active Directory Site Replication Status information." BlankLine $OutObj = @() foreach ($Status in $RepStatus) { try { Write-PscriboMessage "Collecting Active Directory Sites Replication Status from $($Domain). (Sites Replication Status)" $inObj = [ordered] @{ 'Destination DSA' = $Status.'Destination DSA' 'Source DSA' = $Status.'Source DSA' 'Source DSA Site' = $Status.'Source DSA Site' 'Last Success Time' = $Status.'Last Success Time' 'Last Failure Status' = $Status.'Last Failure Status' 'Last Failure Time' = $Status.'Last Failure Time' 'Number of failures' = $Status.'Number of Failures' } $OutObj += [pscustomobject]$inobj } catch { Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Site Replication Status)" } } if ($HealthCheck.Site.Replication) { $OutObj | Where-Object {$_.'Last Failure Status' -gt 0} | Set-Style -Style Warning -Property 'Last Failure Status' } $TableParams = @{ Name = "Site Replication Status - $($Domain.ToUpper())" List = $false ColumnWidths = 14, 14, 14, 15, 14, 15 ,14 } if ($Report.ShowTableCaptions) { $TableParams['Caption'] = "- $($TableParams.Name)" } $OutObj | Table @TableParams if ($HealthCheck.Site.Replication -and ($OutObj | Where-Object {$_.'Last Failure Status' -gt 0})) { Paragraph "Health Check:" -Italic -Bold -Underline Paragraph "Best Practices: Replication failure can lead to object inconsistencies and major problems in Active Directory." -Italic -Bold BlankLine } } } } } catch { Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Site Replication Status)" } } end {} } |