Exchange Powershell command to list if a user is a member of a particular group

I have a commandlet that outputs a list of Exchange users from various databases listed in DBReports.csv, along with various other information. I just added a “Disabled” column, and if the account is disabled, it puts a True in the column and False if it is not. This works fine:

Import-csv "C:\Scripts\DBReports.csv" | foreach { get-mailbox -database $_.ServerDB -resultsize unlimited | select @{Name="DisplayName";expression={$_.displayname}},@{Name="Disabled";expression={(get-Mailbox $_).UserAccountControl -match “AccountDisabled” -match “true”}} } | export-csv "C:\Scripts\Report.csv"

DisplayName      Disabled
Bob Guy                        FALSE
Daniel Person      TRUE
John Human      FALSE

I would like to do the same for an “EV” column, so it populates True or False if the user is a member of “the ev-users-dl” group, but having no luck with the syntax. Here is what I have so far, but that is piecemeal from a few different sources, so I am sure it is all messed up now :)

Import-csv "C:\Scripts\DBReports.csv" | foreach { get-mailbox -database $_.ServerDB -resultsize unlimited | select @{Name="DisplayName";expression={$_.displayname}},@{Name="EV";expression={(Get-distributiongroupmember $_).identity -match “ev-users-dl” -match “true”}} } | export-csv "C:\Scripts\Report.csv"

Any help here would be greatly appreciated!
(Quest tools not installed)

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.

imkotteesSenior Messaging EngineerCommented:

try this out.

$gp = $(Get-Group "GroupName").Identity.DistinguishedName

Get-Mailbox -Filter{(memberofgroup -eq $gp)} | get-mailbox -resultsize unlimited | select @{Name="DisplayName";expression={$_.displayname}},@{Name="Disabled";expression={(get-Mailbox $_).UserAccountControl -match “AccountDisabled” -match “true”}} | export-csv "C:\Scripts\Report.csv"
$members = Get-DistributionGroupMember “the ev-users-dl” | Select -ExpandProperty Alias
Import-csv "C:\Scripts\DBReports.csv" | foreach { get-mailbox -database $_.ServerDB -resultsize unlimited | select DisplayName,@{N="EV";E={If ($members -contains $_.Alias){"True"}Else{"False"}}}} | export-csv "C:\Scripts\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
Vijaya Babu SekarAssociate Ops ManagerCommented:
you may go to below site. so that you can get the script for export the members from particular Distribution group

BelterAuthor Commented:
I could not get imkottees's to work, but thanks Subsun... that worked perfectly!!

BelterAuthor Commented:
This did exactly what I was looking for it to do!! thanks!

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.