powershellexchange-server-2007

Copy members from one Distribution Group to another Distribution Group in PowerShell


**I am trying to copy members from one Distribution group to another Distribution but the members are distribution groups not users\mailbox RecipientType: MailUniversalDistributionGroup

Get-DistributionGroupMember "A" | Get-mailbox | Add-DistributionGroupMember “b”

This doesn't work because members of DL A are Distribution group (nested DLs ) not users **another way I tried **

$bankmanager = Get-DistributionGroupMember -Identity "A" | select DistinguishedName add-distributiongroupmember -Identity "B" -Member $bankmanager

error

getting Add-DistributionGroupMember : Cannot convert 'System.Object[]' to the type 
'Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter' required by parameter 'Member'. Specified method is not supported.**

Solution

  • Here is the code to do what you need:

    Get-DistributionGroupMember -Identity "A" | % {add-distributiongroupmember -Identity "B" -Member $_.Name}
    

    The Add-DistributionGroupMember cmdlet doesn't look like it accepts pipeline inputs like you would normally expect. To get around this I used % which is the pipeline alias for foreach so for each object in the results call add to group. The $_ represents the current object in the for each loop.