need assistance w/POSH script

hi, trying to get this script to export out the 'memberOf' list for user in the target OU's. for some reason, it will not export out the groups the users are a member of.

/code attached.

thx in advance
Get-QADUser -SearchRoot 'ou=accounts,dc=domain,dc=com' -ldapfilter '(sAMAccountName=*)' | select name,memberOf,description | Export-Csv grpresults.csv

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

What is the in the CSV? Nothing? Or just the MemberOf column is empty?
siber1Author Commented:
hi, the memberOf column shows: 'system.String[ ]' when i run that command.
This is because memberOf is a multi-valued property. Try this instead:

Get-QADUser -SearchRoot 'ou=accounts,dc=domain,dc=com' -ldapfilter '(sAMAccountName=*)' | select -expandProperty memberOf | Export-Csv grpresults.csv

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
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

siber1Author Commented:
thx. when i run that command the .csv column is populated with numbers; 66 / 64 / 68 etc
however it does not display the memberOf groups.
I tried it myself, but didn't get that output. Try something like this instead:

Get-QADUser -SizeLimit 0 -SearchRoot '' | select {$_.displayName;$_.description;$_.memberOf | %{$_}} | export-Csv gpresults.csv

Open in new window

(I am aware of the brackets, not sure how to get rid of them)
siber1Author Commented:
Hi, thx..  that does list the memberOf, however it runs all fields together in the CSV.  
how can we format the display to separate out user / display name / memberOf [groupName format]

siber1Author Commented:
I may have found another way to accomplish this, can you tell me how to export this script out to a .CSV?

/see code attached
Get-QADGroup -SizeLimit 30 -SearchRoot '' | ForEach-Object { $_ | Get-QADGroupMember | Select-Object -Property Name,Type,DN | Add-Member -MemberType NoteProperty -Name GroupName -Value $_.Name -PassThru } | Format-Table -GroupBy GroupName | Export-Csv test.csv

Open in new window

siber1Author Commented:
ah.. i found my error on that script . it is working now.

thx for the input!
Get-QADGroup -SizeLimit 30 -SearchRoot '' | ForEach-Object { $_ | Get-QADGroupMember | Select-Object -Property Name,Type,DN | Add-Member -MemberType NoteProperty -Name GroupName -Value $_.Name -PassThru } | Export-Csv test.csv

Open in new window

You have maybe already seen it, but your last script loops through all groups and selects all users in that list. You will therefore end up with many lines per user.
siber1Author Commented:
Hi nordtrop, yes if possible can you post an updated version of your script that separates the user / groupDN?

many thanks
What about this?
It lists all users, as your first approach, and in each line it contains a group membership information.
In lines 5-8 (and of course you can insert additional lines here) you can adjust what information would you like to export. For user attributes use $user. prefix, for group attributes use $_. prefix.
Get-QADUser -SizeLimit 30 -SearchRoot '' -ldapfilter '(sAMAccountName=*)' | %{
    $user = $_
    $user.memberof | Get-QADGroup |%{
        New-Object -TypeName PSObject -Property @{
            Name = $
            UserDn = $user.dn
            GroupName = $
            GroupDN = $_.dn
} | export-csv test.csv

Open in new window

siber1Author Commented:
thanks soostibi, this script is ideal!
exactly what i was looking for
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

From novice to tech pro — start learning today.