Repadmin is legend. I mean, who hasn't impressed their friends, family and pets with the /experthelp switch? And, when it comes to administering and troubleshooting Active Directory replication, repadmin is king. Now, though... there's a young pretender to the throne in the guise of the Windows Server 2012 Active Directory replication cmdlets.
Why use these cmdlets instead of repadmin, you ask? Well, the answer is the same as the answer to the question 'why use a cmdlet instead of an executable'? And here it is...
A cmdlet outputs objects rather than text. An object has a rich set of properties and methods (for getting stuff and doing stuff) that are easily accessed. An object is easily passed down the PowerShell pipeline. Text is, well, just text and it can be quite tricky to parse and manipulate the weird and wonderful patterns returned to the host.
Today, I'm going to try and mimic a popular repadmin command switch, /showrepl, with PowerShell and the AD replication cmdlets. Take a look at the following, hybrid command:
repadmin /showrepl * /csv | ConvertFrom-Csv | Out-GridView
The /showrepl switch tells repadmin to show the inbound replication status, for all partitions for a designated domain controller. The * tells repadmin to execute against ALL domain controllers. The /csv switch produces output that can be saved to a CSV files. If an executable can produce output in a CSV format, it's much easier to get that output into objects so PowerShell can do its amazing stuff. We pipe the output of the repadmin command into ConvertFrom-CSV; the resultant objects are then piped into Out-Gridview for an interactive table. Here's a sample:
Now, let's do something similar with the Get-ADReplicationPartnerMetaData cmdlet:
Get-ADReplicationPartnerMetadata -Target * -Partition * |
Select-Object Server,Partition,Partner,ConsecutiveReplicationFailures,LastReplicationSuccess,LastRepicationResult |
We're targeting all servers the wildcard supplied to the -Target parameter. The wildcard supplied to the -Partition parameter ensures that details for the Schema, Configuration and Domain partitions are included. Select-Object is used to provide a view similar to that of repadmin. Again, Out-Gridview is used to provide an interactive table. Here's a sample:
Right, I'm off to see what other repadmin functionality I can reproduce with the Active Directory replication cmdlets. The king is dead... well, actually, the king is probably going to be round for a little while yet, so long live the young pretender!