locked
Returning ANY property with System.DirectoryServices.DirectorySearcher & whenchanged RRS feed

  • Question

  • OK, so there is this old thread - https://social.technet.microsoft.com/Forums/windowsserver/en-US/15666ba3-ba83-4ceb-9af6-77194072b413/returning-employeeid-property-with-systemdirectoryservicesdirectorysearcher

    which had a nice answer, but I would need to have the property returned only when using whenchanged

    $todaystamp = Get-Date -UFormat %Y%m%d%H%M%S.0Z;
    
    whenchanged>=$todaystamp

    Any idea how?

    Seb


    Thursday, August 9, 2018 5:44 PM

Answers

  • $whenChaned -lt [datetime]::Today

    or

    $searcher = [adsisearcher]'(&(objectCategory=group)(whenChanged<20180828000000.0Z))'


    \_(ツ)_/

    • Marked as answer by scerazy Monday, August 27, 2018 4:27 PM
    Monday, August 27, 2018 10:32 AM

All replies

  • How are you doing this?  "whenChanged" is a property of all objects.  PowerShell does not understand ">=".

    Start by learning basic PwoerShell and the rest will become obvious.

    1. Learn PowerShell  
    2. PowerShell Documentation
    3. PowerShell Style Guidelines


    \_(ツ)_/

    Thursday, August 9, 2018 5:48 PM
  • Here is a starter:

    ([adsisearcher]'samaccountname=jsmith').FindOne() | %{$_.Properties['WhenChanged'][0]}


    \_(ツ)_/

    Thursday, August 9, 2018 5:52 PM
  • You might want to use the Modified PowerShell property, which a normal PowerShell datetime value based on the whenChanged AD attribute. The whenChanged attribute is actually a string, representing datetimes in the format "YYYYMMDDhhmmss.0Z", where YYYY is the 4 digit year, MM the 2 digit month, DD the 2 digit day, hh the 2 digit hour (24-hour clock), mm is the 2 digit minute, and ss is the 2 digit second. The whenChanged value is always in Coordinated Universal Time (UTC), whereas Modified is in the local time zone.

    Edit: The expression given by the OP will be valid using the -LDAPFilter parameter, except that no object should have a whenChanged value greater than the current datetime (it is hoped). It works because the ">=" operator will work on a string in the format of whenChanged, but only with -LDAPFilter.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Thursday, August 9, 2018 6:10 PM
  • "whenChanged under ADSI is a datetime.

    PS U:\> $whenChanged = ([adsisearcher]'samaccountname=jsmith').FindOne() | %{$_.Properties['WhenChanged'][0]}
    PS U:\> $whenChanged
    
    Friday, August 03, 2018 12:06:44 PM
    
    
    PS U:\> $whenChanged.GetType()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     DateTime                                 System.ValueType
    
    
    PS U:\>
    


    \_(ツ)_/

    Thursday, August 9, 2018 7:22 PM
  • Yes, ADSI, and even the command line utility dsquery *, display the values as datetimes. But in an LDAP filter, the string format must be used. I assumed the OP was implying an LDAP filter. For example:

    $searcher = [adsisearcher]'(&(objectCategory=group)(whenChanged>=20180801000000.0Z))'
    The format is called GeneralizedTime


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Thursday, August 9, 2018 10:01 PM
  • The users question is very vague.  It seems to  say he wants to return "whenChanged".


    \_(ツ)_/

    Thursday, August 9, 2018 10:08 PM
  • NO, ideally, I want any property returned (as per this) ONLY when whenChanged is NOT today

    Seb


    • Edited by scerazy Monday, August 27, 2018 9:02 AM
    Monday, August 27, 2018 9:02 AM
  • $whenChaned -lt [datetime]::Today

    or

    $searcher = [adsisearcher]'(&(objectCategory=group)(whenChanged<20180828000000.0Z))'


    \_(ツ)_/

    • Marked as answer by scerazy Monday, August 27, 2018 4:27 PM
    Monday, August 27, 2018 10:32 AM