Powershell script to list users not on a distribution list

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
Mike WalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical SpecialistCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike WalkerAuthor Commented:
Sadly Get-Recipient is not a cmdlet in Exchange 2007
Shaun VermaakTechnical SpecialistCommented:
This person is using it in Exchange 2007. Do you have SP3 CU15+ installed?
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Mike WalkerAuthor Commented:
I'm running Exchange 2007 SP3 UR17
Shaun VermaakTechnical SpecialistCommented:
Mike WalkerAuthor 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.