No announcement yet.

Script to view Mail-Contact users DL's they are members of

  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to view Mail-Contact users DL's they are members of

    I have to migrate about 300 users from Notes to Exchange. These notes users have Mail contact records in AD. I need to start out with a CSV or TXT file with about 20 usernames in that file. Have a script reference that list of users, and output the DL's that those users are members of. I have tried using the below, which I got from the Powershell cookbook, but is not working
    I need to run a script that will show all groups that a user is a member of. I dont want it to run it on every user in AD, just the users in a .txt file.

    So If i have 20 users listed in a .txt or .csv file, will this work?

    Get-Content c:\ Scripts\ users.txt | foreach( $i in Get-DistributionGroup -ResultSize Unlimited) { Get-DistributionGroupMember $i -ResultSize Unlimited | Select-Object @{ n ="Member"; e ={ $_.Name}}, RecipientType, @{ n =" Group"; e ={ $i.Name}} }

    It errors out.

    Unexpected token 'in' in expression or statement.
    At line:1 char:47
    + Get-Content c:\temp\users.txt | foreach( $i in <<<< Get-DistributionGroup -ResultSize Unlimited)

  • #2
    Hi mprisco10. There's a few syntax errors. Also, the script is a bit inefficient as well as there's nothing in the structure to reference the member. Try this code to see if it works for you.

    $Userlist = Get-Content c:\Scripts\users.txt     
    Get-DistributionGroup -ResultSize Unlimited | %{ 
        $grpmems = Get-DistributionGroupMember $
        $grpname = $
        foreach($i in $Userlist) {
            $grpmems | ?{$_.Name -like $($i.Trim())} | Select-Object @{n="Member";e={$_.Name}}, RecipientType, @{n=" Group";e={ $grpname}}
    This is assuming that the list contains the name of the user. If it contains a different user property then the script will need to be changed to reflect that.

    Network Consultant/Engineer
    Baltimore - Washington area and beyond