List All Users Last Logon on specific OU (child OU) Active Directory

Arni 116 Reputation points
2021-03-26T16:51:03.11+00:00

Hi,

I tried this PowerShell script but this is only good for the parent ou. I am looking for the Child OU. How can I modify this PowerShell below or if you could assist in providing a new script, would be great.

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"}}}

Thank you!

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,926 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daisy Zhou 18,716 Reputation points Microsoft Vendor
    2021-03-29T03:30:28.917+00:00

    Hello @Arni ,

    Thank you for posting here.

    Based on the description, I run your command in my lab, it work fine.

    For example:
    We can specify the parent OU (it will list users in parent OU and in all child OU within this parent OU).
    82207-last1.png

    We can We can specify the child OU(it will list users in specific child OU).

    82208-last3.png

    I am sorry, I can not understand what your actual request.

    If anything I misundestood, please feel free to let us know.

    Best Regards,
    Daisy Zhou

    0 comments No comments