Get-ComputerReplicationStatus.ps1
19 Sep 2025Description
Purpose
No synopsis provided.
Detailed Description
No detailed description provided.
Usage
No usage examples provided.
Notes
No additional notes.
Script
function Get-ComputerReplicationStatus {
param (
[string]$ComputerName,
[string[]]$ExcludeDomainControllers
)
# Ensure the ActiveDirectory module is available
if (-not (Get-Module -ListAvailable -Name ActiveDirectory)) {
Write-Error "The ActiveDirectory module is not available. Please install it to use this function."
return
}
# Get all domain controllers
$domainControllers = Get-AllDomainControllers
# Filter out excluded domain controllers if specified
if ($ExcludeDomainControllers) {
$domainControllers = $domainControllers | Where-Object {
$exclude = $false
foreach ($pattern in $ExcludeDomainControllers) {
if ($_.Hostname -like "*$pattern*") {
$exclude = $true
break
}
}
-not $exclude
}
}
# Initialize an array to hold the results
$results = @()
# Iterate over each domain controller and get the computer account details
foreach ($dc in $domainControllers) {
try {
$computer = Get-ADComputer -Identity $ComputerName -Properties * -Server $dc.Hostname
$result = [PSCustomObject]@{
Server = $dc.Hostname
Name = $computer.Name
DNSHostName = $computer.DNSHostName
OperatingSystem = $computer.OperatingSystem
OperatingSystemVersion = $computer.OperatingSystemVersion
LastLogonDate = $computer.LastLogonDate
PasswordLastSet = $computer.PasswordLastSet
Enabled = $computer.Enabled
DistinguishedName = $computer.DistinguishedName
Description = $computer.Description
WhenCreated = $computer.WhenCreated
WhenChanged = $computer.WhenChanged
ManagedBy = $computer.ManagedBy
ServicePrincipalNames = $computer.ServicePrincipalNames -join "; "
}
$result.PSObject.TypeNames.Insert(0, 'Custom.ComputerReplicationStatus')
$results += $result
}
catch {
Write-Warning "Failed to get computer information from server $($dc.Hostname): $_"
}
}
# Return the results
return $results
}
# Example usage:
# Exclude domain controllers with "NYC" in their name:
# $computerStatus = Get-ComputerReplicationStatus -ComputerName "Workstation01" -ExcludeDomainControllers "NYC"
# $computerStatus | Format-Table -AutoSize
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.