I'm trying to enumerate the name, samaccountname, and domain that each user in my forest belongs to and write it to a text file.
The script that I have now is:
Import-Module ActiveDirectory
$domains = "root.org", "child1.root.org", "child2.root.org"
ForEach ($d in $domains){
Get-ADUser -Filter * -ResultSetSize $null -Server $d -Properties name, samaccountname |
Select-Object name, samaccountname | out-file c:\users\mdmarra\desktop\users.txt -append
}
What I need is the value of $d at the end of each line as well so that the output looks like
name samaccountname domain
---- -------------- ------
Marra,Mark mdmarra root.org