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 Specialist/DeveloperCommented:
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

0

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
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
This person is using it in Exchange 2007. Do you have SP3 CU15+ installed?
0
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

Mike WalkerAuthor Commented:
I'm running Exchange 2007 SP3 UR17
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
0
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.
0
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.