Link to home
Start Free TrialLog in
Avatar of mvalencia2003
mvalencia2003Flag for United States of America

asked on

Get AD Usernames - List

What is the full command: "Get-QAD ...

to get all users from a specific OU?

Also to get this list into a file (TXT or XML)
??

-
Thanks,
Avatar of Gary Dewrell
Gary Dewrell
Flag of United States of America image

get-qaduser | where {$_.Path -like "*OU=IT*"}

Output to txt file
get-qaduser | where {$_.Path -like "*OU=IT*"} | Out-File c:\temp\ITMembers.txt

Output to xml
get-qaduser | where {$_.Path -like "*OU=IT*"} | Export-Clixml c:\temp\itmembers.xml
Avatar of mvalencia2003

ASKER

this is searching all accounts in domain: get-qaduser | where {$_.Path -like "*OU=IT*"}

How is OU entered?

Thanks , ...
get-qaduser does not have a built in filter for OU.  You could use the -ldap filter option but I have seen some weirdness from this so the above is what I use in my environment. Let me step you through it.

if you look at a single account:

get-qaduser YourUser | select path
you will see something like this:
LDAP://mydomain.domain.com/CN=Doe\, John,OU=IT,OU=Dallas,DC=mydomain,DC=COM

You have to read it backwards. From this return I see the user Jonhn doe is in the OU IT under the OU Dallas in the mydomain domain.

So If I want to return a list of everyone in the IT OU the above command gets all users and then filters the result by anyone with a path that has the phrase "OU=IT" .

If you were searching for those in the accounting OU you would change it to $_.Path -like "*OU=Accounting*"
so what if OU is: mydomain.domain.com\company\students\group1

??


Thanks , ...
If group1 is unique, i.e. no other OU named group1 then use:

$_.path -like "*group1*"
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question was to get list of users from a specific OU using Get-QADUser command. Solution is to use -SearchRoot parameter as explained in my comment.