extracting nested groups 1 level higher

I have written below code and was able to extract nested group details for only one group. i am not able to give multiple AD groups in this format(A, B, C). Let me know if i can use import-csv -path for below script

Function Get-ADuserNestedGroups
{
param ([string] $distinguishedname, [array]$groups = @()
)
$ADobject = Get-ADObject -filter "distinguishedname -eq '$distinguishedname'" -Properties memberof, distinguishedname;
If ($ADobject)
{
foreach ($groupdistinguishedname in $ADobject.memberof)
{
$currentgroup = Get-ADObject -filter "distinguishedname -eq '$groupdistinguishedname'" -Properties memberof, distinguishedname, samaccountname
If (($groups | Where-Object { $_.distinguishedname -eq $groupdistinguishedname}).count -eq 0)
{
$groups += $currentgroup ;
$groups = Get-ADuserNestedGroups -distinguishedname $groupdistinguishedname -groups $groups
}
}
}
return $groups
}
$nestedgroup = 'NEED TO SPECIFY ad group name' 
$groups = Get-ADuserNestedGroups -distinguishedname (get-adgroup -Identity $nestedgroup).distinguishedname | export-csv C:\Scripts\ADgroup.csv -NoTypeInformation
$groups | select-object name, samaccountname| Sort-Object -Property name