question

ALop-4486 avatar image
0 Votes"
ALop-4486 asked IanXue-MSFT edited

AD Last Logon for specific Sub OU

Hi I need assistance on how I can get a list of users in a specific sub OU (sub container) and exported it out. I have this PowerShell script but it's not recognizing the sub ou , it says cannot find an object with the identity "ABCTestgroup" under DC=IT, DA=ITS

Here is the PowerShell script that I used:

Get-ADGroup ABCtestgroup | Get-ADGroupMember | Get-ADUser -Properties Lastlogondate | Select Name, SamAccountName, LastlogonDate | Export-CSV -Path "c:\temp\ADUsers.csv" -NotypeInformation

ABCtextgroup is sub OU of ABCUsers OU . The goal is to find out if the users within the ABCtextgroup are still active users and if not, I want move them in the nonactive users container.

Thanks

windows-server-powershell
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.

ALop-4486 avatar image
0 Votes"
ALop-4486 answered

Any input? Thanks.

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 IanXue-MSFT edited

Hi,

As ABCtestgroup is an OU, not a group, it does not work with Get-ADGroup. You can get the AD users in the OU like this.

 Get-ADUser -filter * -SearchBase "OU=ABCtextgroup ,OU=ABCUsers,DC=IT,DC=ITS" -Properties Lastlogondate | Select Name, SamAccountName, LastlogonDate | Export-CSV -Path "c:\temp\ADUsers.csv" 

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.