none
PS Scripting Errors RRS feed

  • Question

  • Good Afternoon,

    I'm trying to run script you provided about 4 years agao

    $DGs= Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "user@domain.com"}
     
    foreach( $dg in $DGs){
    Remove-DistributionGroupMember $dg -Member user@domain.com
    }

    But I get an error when I try to run. I do understand that there is programming script error but I don't know how to fix it.

    I'm trying to remove a user from multiple distribution lists by using your script. My environment does not have AD integration at this time.

    I get the error msg below when I try to run your script.

    Cannot process argument transformation on parameter 'Identity'. Cannot convert

    value "ACCESS U.S. Help Desk" to type

    "Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".

    Error: "Cannot convert hashtable to an object of the following type:

    Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter.

    Hashtable-to-Object conversion is not supported in restricted language mode or

    a Data section."

        + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember], 

       ParameterBindin...mationException

        + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Distrib

       utionGroupMember

        + PSComputerName        : pod51048psh.outlook.com

    Any help would be greatly appreciated

    Darren

    Tuesday, April 15, 2014 4:08 PM

All replies

  • It appears the object of your script is to remove a mailbox from all distribution groups it belongs to, correct?  If so, you might try the following scriptlet:

    $MbxDn = (Get-Mailbox "user@domain.com").DistinguishedName
    $Dgs = Get-Group -ResultSize Unlimited -Filter "Members -eq $MbxDN"
    $Dgs | { Remove-DistributionGroupMember $_ -Member $MbxDn }

    Your script is searching all DGs and checking each to see if it has that name as a member.  What I have above filters out all that don't have this as a member, which may work better for you - it's not going through each member of every DL.  (And that may be what's giving you this issue ...)

    Tuesday, April 15, 2014 7:20 PM
  • Willard,

    What I'm trying to do is remove a user, not the mailbox, from all the distribution lists that they are a member of. Yes I could remove them individually thru Power Shell and GUI interface but I would like to remove in one step if possible.

    Darren

    Tuesday, April 15, 2014 9:37 PM
  • So this is an account without a mailbox?  And your script is just to clean up your DL so non-mail-enabled accounts aren't included in it?  If so, the same script I have above will run with a minor change:

    $MbxDn = (Get-User "user@domain.com").DistinguishedName
    $Dgs = Get-Group -ResultSize Unlimited -Filter "Members -eq $MbxDN"
    $Dgs | { Remove-DistributionGroupMember $_ -Member $MbxDn }

    Wednesday, April 16, 2014 11:30 AM