Uptime Legal Systems
asked on
Issue with powershell script / List users in child domains
I have a forest with a number of domains under it, and I need a script that will crawl the directories of the child domains and list the users in each domain. What I have is:
This works and will list users in the C:\ drive labeled to the child domains but in the text file the users are all from the root forest level.
I've tried tweaking this but can't seem to get it to produce the results I need- am I missing something obvious here? Any help is appreciated.
Import-Module ActiveDirectory
(Get-ADForest).domains | % {
Get-ADUser -filter * -SearchBase "$((Get-ADDomain).distinguishedname)" | Select Name, sAMAccountName | Export-CSV "C:\$_ User Accounts.csv" -nti
}
This works and will list users in the C:\ drive labeled to the child domains but in the text file the users are all from the root forest level.
I've tried tweaking this but can't seem to get it to produce the results I need- am I missing something obvious here? Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I believe you are Josh! Thanks again for your previous (and this reply).
I got around to testing on a larger forest and found that it was only listing the users from the top level but it looks like it was a minor change. Thanks again for both of the answers.
I got around to testing on a larger forest and found that it was only listing the users from the top level but it looks like it was a minor change. Thanks again for both of the answers.
You're welcome!
Also, using this
$((Get-ADDomain).distingui shedname) will always return the domain that your user account is in, that was my fault, I didnt think that through.
Rahemans post is incorrect as well.
The proper way for the other script to work is this.
I will post the revised script on the other post as well.
$((Get-ADDomain).distingui
Rahemans post is incorrect as well.
The proper way for the other script to work is this.
Import-Module ActiveDirectory
(Get-ADForest).domains | % {
Get-ADUser -filter * -SearchBase "OU=Accounts,$((Get-ADDomain -Server $_).distinguishedname)" -Server $_ | Select Name,sAMAccountName | Export-CSV "C:\$_ User Accounts.csv" -nti
}
I will post the revised script on the other post as well.
http://www.experts-exchang