List Users Last Logon in specific Sub OU

Arni 116 Reputation points
2021-03-26T16:18:00.693+00:00

Hello I need assistance in finding out users' last logon on a specific sub ou. I used this PS command that I got here in the forum, but this only provides the parent ou not the child ou:

Get-ADUser -filter * -SearchBase 'ou=Offices,DC=contoso,DC=com' -Properties LastLogonTimeStamp | Select sAmAccountName,@{label="LastLogonTimeStamp";Expression={if($.LastLogonTimeStamp){[datetime]::FromFileTime([Int64]$.LastLogonTimeStamp)} Else {"Never"}}}

I need the sub ou members. I would really appreciate if someone could assist. Thank you.

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2021-03-29T08:46:49.643+00:00

    Hi,

    You can simply specify the sub OU

    Get-ADUser -filter * -SearchBase 'OU=subou,OU=Offices,DC=contoso,DC=com' -Properties LastLogonTimeStamp  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Rich Matheisen 48,036 Reputation points
    2021-03-29T02:25:57.567+00:00

    Try adding -SearchScope Subtree to the Get-ADUser cmdlet.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.