Distribution Script to get Write properties and Members

Hello All,
I am trying to retrieve all DLs listing the following
DL names
All users with WriteProperty (not just Managedby)
The Members can Not list down the column but need to show in the same row.  The client is very specific.


The script below is a version of Many I tried to write.  And I need help. Help. Help.

$DGLists=Get-Distributiongroup *  -ResultSize Unlimited
$DGLists | Foreach {Get-ADpermission $DGLists | Where {!$_.IsInherited -and $_.AccessRights -match "WriteProperty"}}| Select Identity,User,@{Name='Access Rights';Expression={[string]::join(";", ($_.AccessRights))}}

{Get-DistributionGroupMember $DGRights -ResultSize Unlimited | Select @{Name='PrimarySmtpAddress';Expression={[string]::join(";", ($_.PrimarySmtpAddress))}}
$DGLists  | Export-Csv C:\xx\DLReport.csv   -NoTypeInformation
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.

$(Foreach ($Group in Get-DistributionGroup -ResultSize Unlimited) {
$Group | Select Name,`
	@{N="WriteProperty";E={($_ | Get-ADpermission | ?{$_.AccessRights -like "*WriteProperty*" -and !$_.IsInherited} | %{$_.User.tostring()}) -join ","}},`
	@{N="Members";E={($_ | Get-DistributionGroupMember -ResultSize Unlimited | Select -ExpandProperty Name) -join ","}}
})| Export-Csv C:\report.csv -NTI

Open in new window

GJohn32Author Commented:
Thank you Subsun,  the script did not work.  I received the error below.

Select-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:1 char:83
+ $(Foreach ($Group in Get-DistributionGroup -ResultSize Unlimited) {$Group | Select <<<<  Name,`@{N="WriteProperty";E={($_ | Get-ADpermission | ?{$_.AccessRights -like "*WriteProperty*" -and !$_.IsIn
herited} | %{$_.User.tostring()}) -join ","}},`@{N="Members";E={($_ | Get-DistributionGroupMember -ResultSize Unlimited | Select -ExpandProperty Name) -join ","}}})| Export-Csv .\DLReport09122013.csv
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
Are you running the code in single line? if yes you need to remove the backtick after each property name after select command..
$(Foreach ($Group in Get-DistributionGroup -ResultSize Unlimited) {$Group | Select Name,@{N="WriteProperty";E={($_ | Get-ADpermission | ?{$_.AccessRights -like "*WriteProperty*" -and !$_.IsInherited} | %{$_.User.tostring()}) -join ","}},@{N="Members";E={($_ | Get-DistributionGroupMember -ResultSize Unlimited | Select -ExpandProperty Name) -join ","}}})| Export-Csv C:\report.csv -NTI

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
GJohn32Author Commented:
Thank you, this worked perfectly
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
Shell Scripting

From novice to tech pro — start learning today.