Using Get-ADReplicationAttributeMetadata

Hi All,

I am trying to create a small script where I will just provide object DN and attribute name and I will get the LastOriginatingChangeDirectoryServerIdentity, but it seems not working. Can you guys please check once and correct me where I am going wrong.

Import-Module ActiveDirectory
$X=Read-Host “Please Enter the object DN”
$Y=Read-Host “Please Enter The Atrribute name”
$Z=Read-Host “Please Entrer The DC name”

Get-ADReplicationAttributeMetadata -Object “$X” -Server $Z |Where-Object {$_.AttributeName -eq ‘$Y’} | Select-Object LastOriginatingChangeDirectoryServerIdentity, LastOriginatingChangeTime |Format-Table -Wrap

Hi Sankar,
The Code Seems working Fine,
Please Cross check the inputs,
and Add Some More Code That checks For Valid Inputs.


Can you shed some more lights in it, I m very new to powershell. Not sure how to code for input valifation. However when I provide my user DN, its unable to find the user… :(. Not sure but is there anything wrong with $X here, as if i would use it for a single user it works. For a single user i would put"" to provide the DN, something is wrong when i use “$X” in the commamd ? Please advise.

One more thing if anyone can help. When i write any ps script, how to i hold the output screen as for this example only if I make it as .ps1 script, after providing the input it would show the output in a screen and the screen would disapper so quickly any idea to keep the result on the ps screen, i dont want to generate any file for the script just need it to be visiable on screen and i would choose to close the screen when i want.

Not sure what you mean about the output screen but if you open the powershell console or ISE you can run your scripts and it stays open until you close it

One problem with your code is

Where-Object {$_.AttributeName -eq ‘$Y’}

You’ve used single quotes but the value of $y won’t be substituted then. You need to use double quotes if you want to substitute variables

Where-Object {$_.AttributeName -eq “$Y”}

Thanks Richard, Yes I do use ISE, But when I make it a ps script, it prompts for the inputs but output disappears so quickly before I can read it. Any idea ?

Also don’t use read-host for input. Create a function and use parameters

function get-ADReplmetadata {
param (


[string]$server = ‘server02’

Get-ADObject -LDAPFilter “($ldapfilter)” -Properties $attribute |
Get-ADReplicationAttributeMetadata -Server $server -Attribute $attribute


Ok Richard, Thanks will see how it works and get back to you.