Any input? Thanks.
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
3 answers
Sort by: Most helpful
-
-
Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,476 Reputation points Microsoft Vendor
2021-03-26T04:00:54.42+00:00 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. -
Qais Mohamed 0 Reputation points
2023-06-20T10:31:33.1333333+00:00 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"