Getting an AD user from specific OU using Powershell RRS feed

  • General discussion

  • Hello,

    I have my search base path in $path and I am trying to get specific user from AD and the search base is $path

    I have following code and it doesnot seem to work:

    $User=Get-Aduser -SearchBase $path -Filter * -properties Name | Where { ($_.Name) -eq $i.Name}

    -SearchBase $path Doesnot seem to work.


    • Changed type Bill_Stewart Monday, April 30, 2018 9:44 PM
    • Moved by Bill_Stewart Monday, April 30, 2018 9:44 PM Unanswerable drive-by question
    Thursday, March 1, 2018 5:14 PM

All replies

  • The $path variable needs to be set to the distinguishedName of an AD container.

    Also, where do the $_ and $i variables come from?

    -- Bill Stewart [Bill_Stewart]

    Thursday, March 1, 2018 5:39 PM
  • Not enough code to know what is happening.

    Does this work?  Is the name you are searching in the list?

    Get-Aduser -SearchBase $path -Filter * |select name, samaccounrtname

    "Name" is a default property it does not need to be specified in "Properties".


    Thursday, March 1, 2018 5:42 PM
  • import-module activedirectory  
    $path = "OU=Computers,DC=grasslands,DC=ab,DC=ca"
    $users = get-aduser -SearchBase $path -filter * -properties name

    This throws me an error saying directory not found. Not sure what I am doing wrong here?

    Thursday, March 1, 2018 5:49 PM
  • Please copy and paste the text of the exact command and the exact error message; please so not paste a screen shot. (Remember: We can't see your screen!)

    -- Bill Stewart [Bill_Stewart]

    Thursday, March 1, 2018 5:55 PM
  • That container doesn't exist.

    $path = 'CN=Computers,DC=grasslands,DC=ab,DC=ca'
    Get-AdObject -SearchBase $path -filter * | select Name

    The computer container is not an OU.  It is just a container.  There should be no users accounts in that location.


    Thursday, March 1, 2018 5:57 PM