locked
Get-ADReplicationAttributeMetadata from .txt file RRS feed

  • Question

  • Hi Expert,

    i wound like to create a simple script to help my junior engineer to get user attribute last modification in easy way. 

    How can i input .txt file to my script below.

    $UserDn = Get-Content -Path "C:\Script\Users.txt" | % {Get-ADUser -Identity $_} | Select-Object DistinguishedName |
    	ForEach-Object{
    		Get-ADReplicationAttributeMetadata "$UserDn" -Server DC01 | sort Lastoriginatingchangetime | select Attributename,LastOriginatingChangeTime, LastOriginatingChangeDirectoryServerIdentity |ogv
    	}

    Thursday, July 5, 2018 6:56 AM

Answers

  • Get-Content C:\Script\Users.txt | 
        Get-ADUser |
        Get-ADReplicationAttributeMetadata | 
        sort Lastoriginatingchangetime | 
        select Attributename,LastOriginatingChangeTime, LastOriginatingChangeDirectoryServerIdentity 


    \_(ツ)_/

    • Marked as answer by Kt, Thursday, July 5, 2018 7:12 AM
    Thursday, July 5, 2018 7:07 AM

All replies

  • Just pipe it:

    Get-Content C:\Script\Users.txt | Get-ADUser

    The file must have identities  and no user names or displaynames.


    \_(ツ)_/

    Thursday, July 5, 2018 7:01 AM
  • Get-Content C:\Script\Users.txt | 
        Get-ADUser |
        Get-ADReplicationAttributeMetadata | 
        sort Lastoriginatingchangetime | 
        select Attributename,LastOriginatingChangeTime, LastOriginatingChangeDirectoryServerIdentity 


    \_(ツ)_/

    • Marked as answer by Kt, Thursday, July 5, 2018 7:12 AM
    Thursday, July 5, 2018 7:07 AM
  • Hi Jrv,

    Your script always so simple and so effective. big hug to you.

    1 question ;)

    What need to add on the script if user (User02) is from different domain.

    Below is the errors when i run on Testingmain.com but user02 is from TestingSub.com

    Get-ADUser : Cannot find an object with identity: 'User02' under: 'DC=Testingmain,DC=com'.
    At line:2 char:5
    +     Get-ADUser |
    +     ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (User2:ADUser) [Get-ADUser], ADIdentityNotFoundException
        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundExcept 
       ion,Microsoft.ActiveDirectory.Management.Commands.GetADUser

    Thursday, July 5, 2018 10:11 AM
  • You will have to use the Global Catalog to find users across domains.  Because of this youo will need to know the user by Distinguished name.


    \_(ツ)_/

    Thursday, July 5, 2018 10:14 AM
  • noted Jrv

    what i will do is removing second line on your script (Get-Aduser |) and ask my junior to fill in the full Distinguished Name on the txt file. hehe

    Thursday, July 5, 2018 10:45 AM
  • That would be the better method and more accurate.

    \_(ツ)_/

    Thursday, July 5, 2018 10:54 AM