• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

Windows PowerShell Exchange Server

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
briousd
Asked:
briousd
  • 23
  • 22
  • 5
  • +3
1 Solution
 
dhruvarajpCommented:
insted of outfile

>users.txt

that should be it
0
 
endital1097Commented:
Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter >c:\users.txt
0
 
endital1097Commented:
Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter | ft displayName,PrimarySmtpAddress > c:\users.txt
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
tspreethCommented:

This should get it.
Get-Recipient –RecipientPreviewFilter $group.RecipientFilter | select name,PrimarySMTPAdress  | out-file C:\users.txt
0
 
briousdAuthor Commented:
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
 
endital1097Commented:
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
 
endital1097Commented:
here is a screenshot from my test
dyn-dg.PNG
0
 
briousdAuthor Commented:
ok, ill retype that and try it.. yes i have been working in EMS. thanks
0
 
briousdAuthor Commented:
ok that works mostly

It keeps returning all exchange users(more than 1000) and not the Group i specify in quotes ???
0
 
endital1097Commented:
i would check the group preview
this should be working
0
 
briousdAuthor Commented:
I double checked the recipient container in EMC where that Dynamic Dist is pointing?
0
 
endital1097Commented:
go to recipient management - distribution groups
go to properties for your group and the conditions tab
you can use the preview button there
0
 
briousdAuthor Commented:
yep, and they show up fine there ?
0
 
GusGallowsCommented:
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
 
briousdAuthor Commented:
sorry what do you mean by copy it to powershell? copy and paste directly into Powershell ?
0
 
briousdAuthor Commented:
ok nevermind got it, same results as before however

the group specified does not work, it keeps outputting all users
0
 
endital1097Commented:
it has to be that dyn dg, i've tested the script on multiple dyn dgs in my environment successfully
0
 
GusGallowsCommented:
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
 
briousdAuthor Commented:
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
 
GusGallowsCommented:
Yes.
0
 
GusGallowsCommented:
Also, run the script against the Dallas group. See if it only return 12 users.
0
 
briousdAuthor Commented:
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
 
GusGallowsCommented:
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
 
endital1097Commented:
we need the conditions tab
0
 
briousdAuthor Commented:
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
 
endital1097Commented:
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
 
briousdAuthor Commented:
sure thing
doc.txt
0
 
endital1097Commented:
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
 
briousdAuthor Commented:
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
 
endital1097Commented:
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
 
briousdAuthor Commented:
no, no problem. It sure looks like there are 215 --they start at A and go all the way to Z
0
 
endital1097Commented:
so then the script is generating the same results as the preview
what should this group be filtered for (department, offce, etc)
0
 
briousdAuthor Commented:
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
 
endital1097Commented:
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
 
briousdAuthor Commented:
this site OU only has 9 recipients
doc2.txt
0
 
endital1097Commented:
can you post the result for the following
Get-Recipient -RecipientPreviewFilter ( get-dynamicdistibutiongroup "Ithaca Employees" ).RecipientFilter | ft displayName,PrimarySmtpAddress
0
 
endital1097Commented:
helps if i spell things correctly
Get-Recipient -RecipientPreviewFilter ( Get-DynamicDistributionGroup "Ithaca Employees" ).RecipientFilter | ft displayName,PrimarySmtpAddress
0
 
briousdAuthor Commented:
it will list all mailboxes and contacts starting at A, up to 1000
0
 
endital1097Commented:
it shouldn't, it should only list mailboxes in the cme.local/Corp/Ithaca/Users OU
0
 
briousdAuthor Commented:
I know, and here lies the frustration.......
0
 
endital1097Commented:
you said it will, i was curious if it did :)
0
 
briousdAuthor Commented:
yes, sorry

so the same results no matter what Dyn DG I use.....?
0
 
endital1097Commented:
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
 
briousdAuthor Commented:
correct
0
 
endital1097Commented:
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
 
briousdAuthor Commented:
thanks a bunch, I have been combing through everything here
0
 
endital1097Commented:
good news, i can reproduce your issue
i should have a solution for you tonight
0
 
sunnyc7Commented:
@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
 
endital1097Commented:
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
 
briousdAuthor Commented:
sunny, PS doesnt recognize that cmdlet

great, at least were not at a complete standstill here
0
 
briousdAuthor Commented:
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
 
sunnyc7Commented:
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
 
sunnyc7Commented:
oops we are filtering dallas ?

get-distributiongroupmember "Dallas"
0
 
endital1097Commented:
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
 
briousdAuthor Commented:
endital, I am in your debt, im glad i could give a challenge
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 23
  • 22
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now