How to get list of users from an OU

Art ODell 1 Reputation point
2022-01-13T21:32:55.24+00:00

First- I am new at powershell. The issue at hand is that I need to get a list of users from an OU who have not logged on in over 90 days. I have a script that gives my all the users but I need to narrow it down to pull just the users from an OU called XXXX Users. How can I modify my script to pull only those from my target OU?

Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 123.6K Reputation points MVP Volunteer Moderator
    2022-01-13T22:11:28.977+00:00

    Hi @Art ODell ,

    maybe these links are helpful:
    https://shellgeek.com/powershell-get-ad-user-not-logged-in-x-days/
    https://www.winsysadminblog.com/2017/07/get-a-list-of-users-in-active-directory-who-have-not-logged-in-for-specified-number-of-days-using-powershell/

    In this examples the command Get-AdUser is used and with -Searchbase you can limit the search on a OU:
    https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-aduser?view=windowsserver2022-ps#example-1--get-all-of-the-users-in-a-container

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.