Try adding -SearchScope Subtree to the Get-ADUser cmdlet.
List Users Last Logon in specific Sub OU

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.
2 answers
Sort by: Most helpful
-
Ian Xue (Shanghai Wicresoft Co., Ltd.) 18,846 Reputation points Microsoft Vendor
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.