This is the best I can do, might need @Rich Matheisen to give it the once over. I've fixed the GC and which DC\Domain it needs to be run from, it now uses a filter based search so it can search the entire forest. Added the logic for multiple users with the same name, but this might not cover all use cases.
[array]$allgcs = Get-ADDomainController -Filter { IsGlobalCatalog -eq $true }
# "Name" is the host portion of the fqdn. If you need the entire fqdn use "HostName" instead
$gc = "$($allgcs[0].hostName):3268" # May not be the best choice for efficiency
# pick one closer to your location, either by your domain or,
# better, by your domain and in your AD site.
# If none are in your site, pick one by lowest cost site
$root = (get-ADRootDSE).RootDomainNamingContext
Import-Csv 'c:\temp\test.csv' |
ForEach-Object {
$row = $_
$name = $_.accounts
foreach ($dn in (Get-ADUser -filter "samaccountname -eq '$name'" -Properties * -Server $gc -searchbase $root).distinguishedName){
Get-ADUser -filter "distinguishedName -eq '$dn'" -Properties "manager" -Server $gc -searchbase $root |
Select-Object @{n = 'Accounts'; e = { $row.Accounts } }, @{n = 'Name'; e = { $_.Name } }, Manager, @{n = 'EMail'; e = { $_.UserPrincipalName } }
}
} | Export-Csv c:\temp\Test-Report.csv -NoTypeInformation
Gary.