#Import-Module ActiveDirectory ## Required Once for script to run
param ($inputfile='.\Users.csv')
## set local variables
$GroupBase = "ou=4,ou=3,ou=2,ou=1,dc=somedomain,dc=net"
$csv = Import-CSV $inputfile
## get all AD Groups from OU Path
$adGroups = @()
$adGroups = Get-ADGroup -filter * -Property Name -SearchBase "$GroupBase" | Sort-Object -Property name
$cleanUsers = @()
foreach($user in $csv){
$sam = $user.Name.Split('@')[0]
$name = @{Name=$sam}
$objUser = New-Object PSObject –Property $name
$cleanUsers += $objUser.Name
}
foreach($g in $adGroups){
$members = Get-ADGroupMember $g
$found = $cleanUsers | W
Write-Output $members
}