Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Get list of distribution groups that user is a member of

$
0
0

We are using Exchange Online at our company. I would like to know how to use PowerShell to get a list of distributions groups that a user is a member of. I have tried several of the other methods listed in these forums, but they do not appear to work with Exchange Online.  For instance, when I run either of the following scripts, I get this error:

Script #1

$User = read-host -Prompt "Enter Username"
"User " + $User + " is a member of the following groups:"

ForEach ($Group in Get-DistributionGroup)
{
   ForEach ($Member in Get-DistributionGroupMember -identity $Group | Where { $_.Name –eq $User })
   {
      $Group.name
   }
}

Script #2

Get-DistributionGroup | where {(Get-DistributionGroupMember $_ | foreach {$_.name}) -contains "member name"}

Error

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "{Distribution Group name}" value of type "Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type "Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMember

When I run this script

Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "user@domain.com" }

I get the following errors:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "{Distribution Group name}" value of type "Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type "Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMember

How can I get this information from Exchange Online?


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>