Export Distribution Group Members... also with Exchange 2003

By YellowOnline on Thursday 7 April 2016 09:46 - Comments (12)
Category: Powershell, Views: 2.783

You need a file with all the users in a specific distribution group? Nowadays Exchange has cmdlets to do this. In Exchange 2003, however, things were rather complicated. Because my environment is still 2003, I made this function to do exactly that.

This snippet also allows for members from different subdomains.



PowerShell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<#   
Created on: 07.04.2016 08:16
Created by: YellowOnline
#>
Function Get-DistributionGroupMembers ($GroupName, $ExportFile = "$GroupName Users.csv", $Delimiter = ';')
    {
    Import-Module ActiveDirectory 
    $arrCN = @(DSQUERY GROUP -Name $GroupName | DSGET GROUP -MEMBERS) #For Exchange 2003, using DSGET is unfortunately the easiest way to do this.
    $arrCN = $arrCN | Where-Object {$_} #Cleans the array from empty entries   
    $GroupUsers = @()
    ForEach ($objCN in $arrCN)
        {
        $ADServer = (([RegEx]::Matches($objCN, '(?i)DC=\w{1,}?\b') | ForEach-Object { $_.Value }) -join ',' ).Replace('DC=','').Replace(',','.') #Some regex magic to extract the domain
        $GroupUsers += Get-ADUser $objCN.Replace('"','') -Server $ADServer #Specifying the domain because some users might come from different domains. This can also take a bit.
        }

    $GroupUsers | Select-Object ObjectClass, Name, GivenName, Surname, @{Name="LoginName";Expression={$_.UserPrincipalName.Split('@')[1].Split('.')[0] + '\' + $_.UserPrincipalName.Split('@')[0]}}`
                | Export-CSV $ExportFile -Encoding UTF8 -Delimiter $Delimiter -NoTypeInformation 
    }




It has three parameters: the group name, the output file name and the delimiter. Only the group name is mandatory. I use the default European delimiter for CSVs: a semi-colon. You might want to change it into comma.

I didn't bother about error-catching by the way. If the group name doesn't exist, you can expect a red screen.

Volgende: Teamviewer on mobile: "Not ready. Please check your connection" 04-'16 Teamviewer on mobile: "Not ready. Please check your connection"
Volgende: Brussels, 22 March 2016 03-'16 Brussels, 22 March 2016

Comments


By Tweakers user walteij, Thursday 7 April 2016 14:50

Uuhm, I would really advise you to start migrating to a more recent version.
Exchange Server 2003 is no longer supported and no updates are released for it anymore. Also Exchange 2003 is only supported on Windows Server 2003, where extended support has ended last year.
So you are now running an internet-connected server, that is no longer receiving updates for both the OS and Exchange.
Sounds like a big risk to me, are you sure you want to take this risk?

By Tweakers user YellowOnline, Thursday 7 April 2016 15:10

walteij wrote on Thursday 07 April 2016 @ 14:50:
Uuhm, I would really advise you to start migrating to a more recent version.
Exchange Server 2003 is no longer supported and no updates are released for it anymore. Also Exchange 2003 is only supported on Windows Server 2003, where extended support has ended last year.
So you are now running an internet-connected server, that is no longer receiving updates for both the OS and Exchange.
Sounds like a big risk to me, are you sure you want to take this risk?
Do you assume that I support an Exchange 2003 because I like it? ;) As far as I am concerned this should me migrated asap. But that is not up to me.

By Tweakers user walteij, Thursday 7 April 2016 15:34

YellowOnline wrote on Thursday 07 April 2016 @ 15:10:
[...]


Do you assume that I support an Exchange 2003 because I like it? ;) As far as I am concerned this should me migrated asap. But that is not up to me.
Sounds like a budget issue, good luck with that.
Maybe you should tell your boss/customer that postponing the migration will only result in higher costs. Migrating Exchange 2003 to 2013 (or 2016) is not possible without third party tools.
Also migrating to Office 365 can only be done with a cutover migration, causing downtime a major out-of-office hours to work.

I assume the hardware it is running on is also at the end of vendor support (no HW maintenance anymore)? Wait untill the server crashes (RAID controller breaks for example) and see how much that will cost (including all mails and data lost).

[Comment edited on Thursday 7 April 2016 17:04]


By Tweakers user YellowOnline, Thursday 7 April 2016 20:11

walteij wrote on Thursday 07 April 2016 @ 15:34:
[...]

Sounds like a budget issue, good luck with that.
Maybe you should tell your boss/customer that postponing the migration will only result in higher costs. Migrating Exchange 2003 to 2013 (or 2016) is not possible without third party tools.
Also migrating to Office 365 can only be done with a cutover migration, causing downtime a major out-of-office hours to work.

I assume the hardware it is running on is also at the end of vendor support (no HW maintenance anymore)? Wait untill the server crashes (RAID controller breaks for example) and see how much that will cost (including all mails and data lost).
I know all of those arguments and it is planned for this year even. Probably this summer. On a side note, I have a lot of legacy stuff. I have 2 NT4s, 89 W2000s and 126 W2003s left in my environment :+. (And 1420 XPs!)

By Tweakers user Jeoh, Thursday 7 April 2016 20:14

Why not just use Get-ADGroupMember?

By Tweakers user i-chat, Thursday 7 April 2016 21:41

I know all of those arguments and it is planned for this year even. Probably this summer. On a side note, I have a lot of legacy stuff. I have 2 NT4s, 89 W2000s and 126 W2003s left in my environment :+. (And 1420 XPs!)
can you tell us for which company this is, i would like to know with who'm i should never do busyness

[Comment edited on Thursday 7 April 2016 21:42]


By Tweakers user servies, Friday 8 April 2016 08:24

YellowOnline wrote on Thursday 07 April 2016 @ 20:11:
[...]


I know all of those arguments and it is planned for this year even. Probably this summer. On a side note, I have a lot of legacy stuff. I have 2 NT4s, 89 W2000s and 126 W2003s left in my environment :+. (And 1420 XPs!)
I'll beat that with a single Windows 95 computer that's running somewhere in the factory where I'm working on the MIS... Unfortunately it can't be replaced as there's no modern replacement...

By Tweakers user servies, Friday 8 April 2016 08:25

i-chat wrote on Thursday 07 April 2016 @ 21:41:
[...]


can you tell us for which company this is, i would like to know with who'm i should never do busyness
I think you'll be amazed at the number of companies still using outdated/obsolete software. And often that's not a choice...

By Tweakers user Dennism, Friday 8 April 2016 11:23

servies wrote on Friday 08 April 2016 @ 08:25:
[...]

I think you'll be amazed at the number of companies still using outdated/obsolete software. And often that's not a choice...
Its always a choice, for every piece of software a alternative is available or can be designed and programmed from the ground up inline with modern standards and current business needs. The question only often is if there are cost effective alternatives and building up from the ground if often dismissed as to expensive on the short term. But even if you make the choice not to migrate to a alternative or new software package its still a choice.

Problem is though that alot of companies only think short term, and not long term.

By Tweakers user m-vw, Friday 8 April 2016 11:33

i-chat wrote on Thursday 07 April 2016 @ 21:41:
[...]


can you tell us for which company this is, i would like to know with who'm i should never do busyness
A bit short sighted don't you think?

By Tweakers user Qwerty-273, Saturday 9 April 2016 16:51

Dennism wrote on Friday 08 April 2016 @ 11:23:
Its always a choice. The question only often is if there are cost effective alternatives and building up from the ground if often dismissed as to expensive on the short term. But even if you make the choice not to migrate to a alternative or new software package its still a choice.
Problem is though that alot of companies only think short term, and not long term.
Nope, even leaders in high-end segments where their own products are market leaders, they internally stick to old and "proven" technology. There is no business drive to upgrade - just because it is newer / fancier. I have seen examples where the conservative N-1 strategy in software usage, turned with time into N-5 (since that one was still supported...). If you think it was "lack" of money, no - stock holders were receiving nice returns on their investments (both stock prices going up as well as dividends).....
How will you think long term, when solution cycles are 2 - 2.5 years? And life cycles of these solutions are much longer. Will you upgrade to always the most current version, or do you allow to remain on a lower version - which is still supported and still receives updates both functional and security wise. To link it back to Exchange, which flavour do you chose? 2003/2007/2010/2013/2016? Or will you move to the cloud with O365 (and basically run always the latest Exchange version)?

By Tweakers user servies, Friday 15 April 2016 13:27

servies wrote on Friday 08 April 2016 @ 08:24:
[...]

I'll beat that with a single Windows 95 computer that's running somewhere in the factory where I'm working on the MIS... Unfortunately it can't be replaced as there's no modern replacement...
I'm going to improve on this one...
We also have a Windows 3.11 computer running somewhere... ;(
It's connected to a CNC machine which hasn't been replaced yet and for which there's no more recent software available...

[Comment edited on Friday 15 April 2016 13:28]


Comments are closed