question

Arni-3472 avatar image
0 Votes"
Arni-3472 asked IanXue-MSFT answered

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.

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.