The quoting used in the filter string is wrong:
Get-ADGroup -Filter "CN -like '$groupmemberof'"-Properties MemberOf |
Select-Object -ExpandProperty MemberOf
If you surround the string with single-quotes you prevent the interpolation of the variable $groupname. Instead, use double-quotes around the whole string and single-quotes around the variable.