Rename a distribution group in Exchange with Powershell

Recently I was asked to rename some distribution groups in Exchange. Not so tough of a problem, but painstaking to do one at a time and there were a few of these to do. So I did what any good admin should do, I wrote a script to take care of this.

The issues
To properly rename a distribution group, you need to not only change the name of the group, but also the Alias, DisplayName and entries in the EmailAddresses field. The first two are easy but if you’re like me, you need to add a handful of emailaddresses to these fields. In our environment, we tend to add records when a name is changed rather than swap the old for the new. This way, if someone uses the old address, it still goes to where they want it too. Probably a better answer would be to create a mailbox with the old address and setup an auto reply that says “Hey, use the new address for this list.” That’ll be for another day.

Anyways, here is the script…
I should note, that I’m keeping this function (along with some other Exchange functions on github. you can get the most recent version of this script here:


Some things worth noting

First of all, I’m working trying to make every bit of code I write more of a tool for others rather than something I use in my environment only. As a result, I’m utilizing ShouldContinue and ShouldProcess more. In this script I use them twice. First when I change the Name, Alias and DisplayName fields

The second time I use ShouldProcess and ShouldContinue is when I set the EmailAddresses field.

Also, you’ll notice there isn’t much in the way of actual comments. This is a bit of a departure for me as I love my comments. But, rather than use comments, I’ve decided to use Write-Verbose so that everyone can share in “What should be happening.”

Let me know if you have any questions, or if you think there is a better way.


7 thoughts on “Rename a distribution group in Exchange with Powershell

  1. Hi Gene,

    stupid question, as I am not very familiar with PS:
    How do you run that script / call the function from PS?
    I tried:

    . .\rename_distribution_groups.ps1
    Rename-DistributionGroup -OldName “MyOldGroupName” -NewName “MyNewGroupName”

    I just receive an error “… a parameter with the name “confirm” was defined multiple times…”

    If I add that param, same result:
    Rename-DistributionGroup -OldName “MyOldGroupName” -NewName “MyNewGroupName” -confirm

    Could you pls advise?

    Thx in advance

    • Hi Dan,
      Looks like you are doing it correctly. try -confirm:$false (if you want it to just run) or -Confirm:$True (if you want it to check with you first).

      • Gene,

        I’ve tried adding the -confirm parameter the same way you describe, but I still get the same exception: “…A parameter with the name “confirm” was defined muliple times…”

  2. Just to confirm (pun intended?), I am getting the same error. No matter what I do (even trying get-help rename-distributiongroup), I get the “A parameter with the name ‘Confirm’ was defined multiple times for the command’.

  3. This was probably written in the Powershell V2 era. Confirm is now provided by default and could be removed?

    [string] $OldName,
    [string] $NewName

Leave a Reply