Solved

Windows PowerShell Exchange Server

Posted on 2010-08-31
55
642 Views
Last Modified: 2012-08-13
Hello

I am trying to export a dynamic distribution group to a text file. I am able to export the Names but i need the users primary smtp address also, how do I apply that string in there as well.

here is what i have, im using two commands

$group = get-dynamicdistibutiongroup -identity "Exchange Email Users"

then i run

Get-Recipient -RecipientPreviewFilter $group.RecipientFilter | out-file c:\users.txt
0
Comment
Question by:briousd
  • 23
  • 22
  • 5
  • +3
55 Comments
 
LVL 10

Expert Comment

by:dhruvarajp
Comment Utility
insted of outfile

>users.txt

that should be it
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter >c:\users.txt
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter | ft displayName,PrimarySmtpAddress > c:\users.txt
0
 
LVL 2

Expert Comment

by:tspreeth
Comment Utility

This should get it.
Get-Recipient –RecipientPreviewFilter $group.RecipientFilter | select name,PrimarySMTPAdress  | out-file C:\users.txt
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
thanks folks for the reply,

--endital1097, PS come back with an error that it doesnt recognize the (get-dynamicdistibutiongroup....

--tspreeth, i get the results piped to a text file but it seems that it always grabs every user. For example we have a Dynamic Group called "Dallas" which only has 12 users that have email. The dynamic distibution filter is set to our Dallas OU
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
you should be able to use the tab key for each part. just make sure to put a space between the ( and get-dyn
this also must be run from the exhcange management shell

Get-Rec<TAB> -recip<TAB> ( get-dyna<TAB> "Group name" ).RecipientFilter | ft...

Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter | ft displayName,PrimarySmtpAddress > c:\users.txt
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
here is a screenshot from my test
dyn-dg.PNG
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
ok, ill retype that and try it.. yes i have been working in EMS. thanks
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
ok that works mostly

It keeps returning all exchange users(more than 1000) and not the Group i specify in quotes ???
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
i would check the group preview
this should be working
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
I double checked the recipient container in EMC where that Dynamic Dist is pointing?
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
go to recipient management - distribution groups
go to properties for your group and the conditions tab
you can use the preview button there
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
yep, and they show up fine there ?
0
 
LVL 12

Expert Comment

by:GusGallows
Comment Utility
I do it as follows:
-----------------------------------------Beginning of script---------------------------------------------
#create a function to produce list of recipients of a Dynamic Distribution Group
Function get-DDGMembers($GroupName)
{
      #create an output file based on the group name.
                     $out = "C:\" + $GroupName + ".txt."
      
                     # Gather the recipients
                     $Path = (Get-DynamicDistributionGroup -identity $GroupName).RecipientFilter
      $rec = @(Get-Recipient -ResultSize Unlimited -RecipientPreviewFilter $Path)

                     #go through the list of recipients and pull the info you need.
      Foreach ($item in $rec)
      {
            $name = $item.name
            $mbx = Get-Recipient $Name
            $dn = $mbx.DisplayName
            $addr = $mbx.PrimarySmtpAddress.Local + "@" +  $mbx.PrimarySmtpAddress.Domain
            $inp = "$DN`t$addr"
            Out-File $out -inputobject $inp -Append            
      }
}
-----------------------------------------End of script---------------------------------------------
To run this function, copy the whole script to your powershell then run the following command:
get-DDGMembers "Exchange Email Users"

This will create a tab delimited output file with the list of users and their primary SMTP addresses.

0
 
LVL 3

Author Comment

by:briousd
Comment Utility
sorry what do you mean by copy it to powershell? copy and paste directly into Powershell ?
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
ok nevermind got it, same results as before however

the group specified does not work, it keeps outputting all users
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
it has to be that dyn dg, i've tested the script on multiple dyn dgs in my environment successfully
0
 
LVL 12

Expert Comment

by:GusGallows
Comment Utility
Just to understand, is the dynamic distribution group actually called Exchange Email Users? If it is Dallas, then run it with get-DDGMembers "Dallas"


If "Exchange Email Users" is the group, Copy and paste the filter for it so we can see it. You can get the filter from Exchange Management Console.
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
yes for this one it is called Exchange Email Users. do you just want what is on the filter tab in the properties of that group ?
0
 
LVL 12

Expert Comment

by:GusGallows
Comment Utility
Yes.
0
 
LVL 12

Expert Comment

by:GusGallows
Comment Utility
Also, run the script against the Dallas group. See if it only return 12 users.
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
i ran the script on 5 different dynamic groups that display fine when i preview them in EMC, also
they work properly when users pick them from the GAL
email-users.jpg
0
 
LVL 12

Expert Comment

by:GusGallows
Comment Utility
The filter you are using on this group will give you all Users with Exchange mailboxes. So it is working as it is supposed too... I am not sure what issue you are having?
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
we need the conditions tab
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
Gus, the issue is no matter what dynamic group i specify it keeps returning all users(user mailboxes,user contacts). So if i use a dynamic group that I know should return a small amount of users it will not work, it keeps returning with over 1000 recipients

attatched is the conditions tab

i'm suprised you guys are still hanging on to this issue, I appreciate it greatly
emailusers1.tiff
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
can you run and post results
 get-dynamicdistributiongroup "Exchange Email Users" | fl

the image doesn't show everything and this result will give us all the information we need from the group
thanks
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
sure thing
doc.txt
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 32

Expert Comment

by:endital1097
Comment Utility
thanks, i got what i needed from that
as you can see the recipient container (the OU you wanted to filter on) is the only filter. this dynamic dg will contain all mailboxes within this ou
so if you run the following it should match the number of users from the scripts earlier
(get-mailbox -organizationalunit acme.local/Corp).Count

RecipientContainer                 : acme.local/Corp
RecipientFilter                    : (RecipientType -eq 'UserMailbox' -and -not(Name -like 'SystemMailbox{*')
                                      -and -not(Name -like 'CAS_{*'))
LdapRecipientFilter                : (&(objectClass=user)(objectCategory=person)(mailNickname=*)(msExchHomeSe
                                     rverName=*)(!(name=SystemMailbox{*))(!(name=CAS_{*)))
IncludedRecipients                 : MailboxUsers

0
 
LVL 3

Author Comment

by:briousd
Comment Utility
yep, and the groups work when users use them from the Global address list

the count says 215 mailboxes, when i run your script or Gus's it display's every user, and it doesnt matter what Dyn DG I use
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
i'm sorry if this is a repeat, but in the console when you go to the conditions tab and click preview it does not show all 215, correct
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
no, no problem. It sure looks like there are 215 --they start at A and go all the way to Z
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
so then the script is generating the same results as the preview
what should this group be filtered for (department, offce, etc)
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
the AD structure is

acme.local

then corp

underneath corp is all of our sites, all with there respective OU's with users and computers

the Dyn DG's all point to the Users' OU

in the case of the "Exchange Email Users" the filter points to corp

0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
the filter recipient container filter includes all sub OUs
so the "Exchange Email Users" should have everyone

can you run the get-dynamicdistributiongroup | fl cmdlet for one of the other OUs
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
this site OU only has 9 recipients
doc2.txt
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
can you post the result for the following
Get-Recipient -RecipientPreviewFilter ( get-dynamicdistibutiongroup "Ithaca Employees" ).RecipientFilter | ft displayName,PrimarySmtpAddress
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
helps if i spell things correctly
Get-Recipient -RecipientPreviewFilter ( Get-DynamicDistributionGroup "Ithaca Employees" ).RecipientFilter | ft displayName,PrimarySmtpAddress
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
it will list all mailboxes and contacts starting at A, up to 1000
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
it shouldn't, it should only list mailboxes in the cme.local/Corp/Ithaca/Users OU
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
I know, and here lies the frustration.......
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
you said it will, i was curious if it did :)
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
yes, sorry

so the same results no matter what Dyn DG I use.....?
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
and just for sanity sake, when you go in the console and properties for this one
the conditions tab preview results are as expected?
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
correct
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
i am going to add more complexity to my lab and test some more
i also sent this question to another expert for his thoughts
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
thanks a bunch, I have been combing through everything here
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
good news, i can reproduce your issue
i should have a solution for you tonight
0
 
LVL 28

Expert Comment

by:sunnyc7
Comment Utility
@endital thanks for the heads-up.

I believe this >> Get-DynamicDistributionGroup "Ithaca Employees"
is not a filterable property of get-recipient

let me ask you this (sounds kinda dummy...)

did you try

get-distributiongroupmember "Exchange Email Users"
0
 
LVL 32

Accepted Solution

by:
endital1097 earned 500 total points
Comment Utility
since your dynamic distribution group only filters on ou

i am still trying to determine if there is a better way
$group = Get-DynamicDistributionGroup "Dallas"

Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer | ft displayName,primarysmtpaddress

Open in new window

0
 
LVL 3

Author Comment

by:briousd
Comment Utility
sunny, PS doesnt recognize that cmdlet

great, at least were not at a complete standstill here
0
 
LVL 3

Author Comment

by:briousd
Comment Utility
endital, nice, so i ran the above script and the results display like they should

and all because I had the filter set at the OU level ?
0
 
LVL 28

Expert Comment

by:sunnyc7
Comment Utility
What version of exchange are you running ? You mentioned Exchange 2007 SP2 in your queues.

http://technet.microsoft.com/en-us/library/aa996367(EXCHG.80).aspx
0
 
LVL 28

Expert Comment

by:sunnyc7
Comment Utility
oops we are filtering dallas ?

get-distributiongroupmember "Dallas"
0
 
LVL 32

Expert Comment

by:endital1097
Comment Utility
yes, i kicked myself for being so silly
the get-recipient cmdlet is used to get a list of recipients
the recipientpreviewfilter allows you to filter the results, we were using the dynamic distribution groups recipient filter for this but your only true filter was that it be a mailbox (the OU filter is not part of that filter)
since you are filtering by OU you need to add that for your get-recipient filter
you want to be consistent so it is best to pull that value from the dynamic distribution group

you should be all set
0
 
LVL 3

Author Closing Comment

by:briousd
Comment Utility
endital, I am in your debt, im glad i could give a challenge
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
how to add IIS SMTP to handle application/Scanner relays into office 365.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now