Export-csv creating multiple lines

So I have found this script that is exactly what I need to export lastlogon and memberof to a .csv file. The problem is the output lists the group memberships on multiple lines instead of just one -

I believe the answer is using (join “,”) instead of (Split ('.')) but I can seem to find where to make the edit to obtain the correct results.

Any help would be greatly appreciated, thank you.

$results = @()
$users = Get-ADUser u11111 -Properties Name,Description,Enabled,lastLogon,MemberOf
foreach($user in $users){
    $lastlogon = [datetime]::FromFileTime($user.lastlogon)
    foreach($group in $user.MemberOf){
        $temp = New-Object PSCustomObject -Property @{'Name' = $user.Name;
                                                      'Description' = $user.Description;
                                                      'Enabled' = $user.Enabled;
                                                      'LastLogon' = $lastlogon;
                                                      'Group' = '';
        }
        $temp.Group = $group.Split(',')
        $results += $temp
    }
}
$results | Export-CSV C:\Output\ADDumpu57167.csv -NoTypeInformation
LVL 1
AAP_MidrangeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
What I see is that the split is an attempt to get just part of the group's distinguishedName (unsuccessfully, because the code isn't right).  Other than that the split doesn't do anything in the above.

If you just want your output to include everything in the memberof property, then you can use the below.  Modified as little as possible so you can spot the code difference.
$results = @()
$users = Get-ADUser testuser -Properties Name,Description,Enabled,lastLogon,MemberOf
foreach($user in $users){
    $lastlogon = [datetime]::FromFileTime($user.lastlogon)
    $temp = New-Object PSCustomObject -Property @{'Name' = $user.Name;
                                            'Description' = $user.Description;
                                            'Enabled' = $user.Enabled;
                                            'LastLogon' = $lastlogon;
                                            'Group' = "$($user.memberof -join ';')";
                                            }
    $results += $temp
}
$results | Export-CSV ee-temp1.csv -NoTypeInformation

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AAP_MidrangeAuthor Commented:
I think this will work but it is producing an unknown file...please see screen shot.
C--Users-u57167-Documents-FileDump-G.PNG
AAP_MidrangeAuthor Commented:
Please disregard the file issue, that was my fault and I have resolved it. This is exactly what I need, thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.