Powershell script to display all groups and their users

Get-AdGroup -filter * |
    ForEach-Object{
        $groupname=$_.Name
        Get-ADGroupMember $_ |
            ForEach-Object{
                [pscustomobject]@{
                    GroupName=$groupname
                    Name=$_.name
                    SamAccountNamename=$_.samaccountname
                }
            }
    }

You need to initialize $objRecord as an Array:

$objRecord = @()

Then you can += it.

Also, you should just do:

$objRecord += New-Object PSObject -property $Record $Table

instead of:

$objRecord = New-Object PSObject -property $Record $Table += $objrecord

I.e.: you're doing 2 assignments. You either do a=a+1 or a+=1.

I'd go with Steve's answer, though.