File.csv contains a list of groups that are in different domains. I'm trying to recursively pull the list of users in the list but it keeps giving me the following at at $adgroup:"No positional parameter found"
$groups = Get-Content -path 'C:\Temp\test.csv'
$domains = (Get-ADForest).Domains
$result = foreach ($group in $groups)
{
foreach ($domain in $domains)
{
$adGroup = Get-ADGroup $group -SearchBase "" -Server thegc3268
$x = ($.DistinguishedName -split ‘,DC=‘)[1]
$members = (Get-ADGroupMember $adGroup -Server $x -recursive).where({
$_.ObjectClass -eq 'User'
})
foreach($user in $members)
{
[pscustomobject]@{
GroupName = $adGroup.Name
samAccountName = $user.samAccountName
distinguishedName = $user.distinguishedName
name = $user.name
}
}
}
}
$result | Export-Csv c:\temp\testing.csv -NoTypeInformation