none
Powershell: Combining two filters RRS feed

  • Question

  • I can used Get-AdGroupMember to return a list of users in a security group and Get-ADUser to list users not logged on in the last 90days. What I can't work out is how to combine this into a single query so that I get a list of all users in the security group who have not logged on in 90 days.
    • Moved by Bill_Stewart Friday, July 27, 2018 6:28 PM Abandoned
    Monday, April 30, 2018 11:43 PM

All replies

  • What have you tried?

    To get users of a group:

    Get-AdGroupMember | Get-AdUser -Properties LastLogonDate 


    \_(ツ)_/

    Tuesday, May 1, 2018 1:09 AM
  • Using Get-ADUser you can filter on users where LastLogonDate is less than a date 90 days in the past, and memberOf equals the distinguished name of a group. If you need to consider membership in the group due to group nesting, you can use the -LDAPFilter parameter, which supports LDAP_MATCHING_RULE_IN_CHAIN, which reveals membership due to group nesting.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Tuesday, May 1, 2018 2:20 AM
  • I tried the following but I am obviously not understanding something as I am not getting the expected results

    Get-AdGroupMember -Identity "ENG-USERS.eng" | Get-AdUser -Properties LastLogonDate -Filter {LastLogonDate -lt "01/01/2018"} | Export-Csv C:\temp\Inactive.csv –NoTypeInformation

    Basically  I want to export all users in the ENG-USERS.eng security group that have not logged on since the beginning of this year. I appear to be getting all users and not just those in the list group.

    Tuesday, May 1, 2018 5:21 AM
  • Get-AdGroupMember ENG-USERS.eng |
        where{$_.ObjectClass -eq 'User'} |
        Get-AdUser -Properties LastLogonDate |
        Where{$_.LastLogonDate -le [datetime]'01/01/2018'}


    \_(ツ)_/


    • Edited by jrv Tuesday, May 1, 2018 5:33 AM
    Tuesday, May 1, 2018 5:32 AM
  • I like this:

    Get-ADUser -Filter {(LastLogonDate -le [datetime]'01/01/2018') -And (memberOf -eq 'cn=ENG-USERS.eng,ou=West,dc=Domain,dc=com')}
    


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Tuesday, May 1, 2018 11:27 AM