Solved

Windows PowerShell Exchange Server

Posted on 2010-08-31
55
649 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 23
  • 22
  • 5
  • +3
55 Comments
 
LVL 10

Expert Comment

by:dhruvarajp
ID: 33569079
insted of outfile

>users.txt

that should be it
0
 
LVL 32

Expert Comment

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

Expert Comment

by:endital1097
ID: 33569120
Get-Recipient -RecipientPreviewFilter (get-dynamicdistibutiongroup "Exchange Email Users" ).RecipientFilter | ft displayName,PrimarySmtpAddress > c:\users.txt
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 2

Expert Comment

by:tspreeth
ID: 33569207

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

Author Comment

by:briousd
ID: 33569940
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
ID: 33569977
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
ID: 33569994
here is a screenshot from my test
dyn-dg.PNG
0
 
LVL 3

Author Comment

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

Author Comment

by:briousd
ID: 33570223
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
ID: 33570298
i would check the group preview
this should be working
0
 
LVL 3

Author Comment

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

Expert Comment

by:endital1097
ID: 33570584
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
ID: 33570661
yep, and they show up fine there ?
0
 
LVL 12

Expert Comment

by:GusGallows
ID: 33571036
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
ID: 33571650
sorry what do you mean by copy it to powershell? copy and paste directly into Powershell ?
0
 
LVL 3

Author Comment

by:briousd
ID: 33571943
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
ID: 33572364
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
ID: 33576265
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
ID: 33576566
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
ID: 33576741
Yes.
0
 
LVL 12

Expert Comment

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

Author Comment

by:briousd
ID: 33577423
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
ID: 33577451
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
ID: 33577460
we need the conditions tab
0
 
LVL 3

Author Comment

by:briousd
ID: 33577845
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
ID: 33577937
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
ID: 33578286
sure thing
doc.txt
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33578366
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
ID: 33578609
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
ID: 33578954
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
ID: 33579026
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
ID: 33579047
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
ID: 33579181
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
ID: 33579275
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
ID: 33579810
this site OU only has 9 recipients
doc2.txt
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33579894
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
ID: 33579899
helps if i spell things correctly
Get-Recipient -RecipientPreviewFilter ( Get-DynamicDistributionGroup "Ithaca Employees" ).RecipientFilter | ft displayName,PrimarySmtpAddress
0
 
LVL 3

Author Comment

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

Expert Comment

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

Author Comment

by:briousd
ID: 33580106
I know, and here lies the frustration.......
0
 
LVL 32

Expert Comment

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

Author Comment

by:briousd
ID: 33580257
yes, sorry

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

Expert Comment

by:endital1097
ID: 33580379
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
ID: 33580507
correct
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33580525
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
ID: 33580644
thanks a bunch, I have been combing through everything here
0
 
LVL 32

Expert Comment

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

Expert Comment

by:sunnyc7
ID: 33580931
@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
ID: 33580968
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
ID: 33581175
sunny, PS doesnt recognize that cmdlet

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

Author Comment

by:briousd
ID: 33581214
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
ID: 33581216
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
ID: 33581248
oops we are filtering dallas ?

get-distributiongroupmember "Dallas"
0
 
LVL 32

Expert Comment

by:endital1097
ID: 33581356
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
ID: 33581486
endital, I am in your debt, im glad i could give a challenge
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

734 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