Powershell script to list users not on a distribution list

Mike Walker
Mike Walker used Ask the Experts™
on
I have an Exchange 2007 server and am needing a powershell script to look at a distribution list with nested distribution lists inside of it and then export a csv of all the mailboxes not in this distribution list.

The DL looks similar to this:
entirecompanydl
  dept 1
    dept1 directors office
    dept1 people
  dept 2
    dept2 directors office
    dept 2 people
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Please test
$groupName = "Some Group 1";
$allEmailAddresses = Get-Recipient | Select Name -ExpandProperty EmailAddresses | Select Name,  SmtpAddress;
$membersOfGroup = get-adgroupmember $groupName -recursive | get-aduser -properties mail | select-object mail;
$allEmailAddresses| Where {$membersOfGroup -notcontains $_.mail};

Open in new window

Author

Commented:
Sadly Get-Recipient is not a cmdlet in Exchange 2007
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
This person is using it in Exchange 2007. Do you have SP3 CU15+ installed?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I'm running Exchange 2007 SP3 UR17
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:

Author

Commented:
I guess by default I was running it in powershell without the Exchange snapin. When I threw in:

"add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin"

Everything worked.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial