<# .SYNOPSIS Retrieves the replication summary for all domain controllers in the specified Active Directory domain. .DESCRIPTION This script runs the repadmin /replsummary command on each domain controller in the specified Active Directory domain and saves the output to a text file. .EXAMPLE .\Get-Replsummary.ps1 This command runs the script, which retrieves the replication summary for all domain controllers in the specified Active Directory domain and saves the output to text files in the C:\Temp\DCDIAG folder. .EXAMPLE Get-Replsummary.ps1 | Out-File -FilePath "ReplSummaryReport.txt" This command runs the script and saves the combined output of all replication summaries to a text file named "ReplSummaryReport.txt" in the current directory. .INPUTS None. This script does not accept any input from the pipeline. The Microsoft .NET Framework type of the objects that the cmdlet returns (if any). You can also include a description of the returned objects. .NOTES Ensure that you have the necessary permissions to run repadmin on the domain controllers in your Active Directory environment. The script saves individual replication summaries for each domain controller in the C:\Temp\DCDIAG folder. Adjust the output folder path as needed for your environment. #> #Import Active Directory module Import-Module ActiveDirectory #Get all DCs from the Domain Controllers OU $domainControllers = Get-ADComputer -SearchBase "OU=Domain Controllers,DC=youdomain,DC=net" ` -Filter * ` -Properties Name | Select-Object -ExpandProperty Name #Output files for each DC $OutputFolder = "C:\Temp\DCDIAG" New-Item -Path $OutputFolder -ItemType Directory -Force | Out-Null foreach ($dc in $domainControllers) { Write-Host "Running repadmin /replsummary on $dc..." $session = New-PSSession -ComputerName $dc $result = Invoke-Command -Session $session -ScriptBlock { repadmin /replsummary } #Save the result to the outfolder folder where this script runs $filePath = Join-Path -Path $OutputFolder -ChildPath "$dc.txt" $result | Out-File -FilePath $filePath -Encoding UTF8 Remove-PSSession -Session $session } Write-Host "All replication summaries saved to $OutputFolder" Start-Process $OutputFolder