Bulk rename of exchange 2010 distribution list

I need to use the Exchange cmdlet Set-distributionGroup to change 100 DL.  I have a csv file that list the old names, new names, primarysmtpaddress columns.   How can I accomplish this using the these cmdlets import-csv and set-distributiongroup.  Can you provide me with the correct syntax?
JCJohnson76Asked:
Who is Participating?
 
Will SzymkowskiSenior Solution ArchitectCommented:
JC, I have tested this in my lab and i have added 5 entries and it works completely fine. What you could try is the following...
$DisLists = Import-csv c:\filename.csv
ForEach ($Dis in $DisLists) {
$Dis.Oldsmtpaddress
$Dis.Alias
$Dis.Primarysmtpaddress
$Dis.NewName
$Dis.DisplayName
Set-DistributionGroup -Identity $Dis.Oldsmtpaddress -Name $Dis.NewName -PrimarySMTPAddress $Dis.Primarysmtpaddress -Alias $Dis.Alias -DisplayName $Dis.DisplayName
}

Open in new window


The above also works for me. Not sure why the first one does not work for you.

Will.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Use the following command...

All you need is PrimarySMTPAddress and NewName Column.

Construct your csv like below...
PrimarySMTPAddress             NewName
dis1@domain.com                       Dis1
dis2@domain.com                       Dis2
etc...

$DisLists = Import-csv c:\filename.csv
ForEach ($Dis in $DisLists) {
$Dis.Primarysmtpaddress
$Dis.NewName
Get-DistributionGroup -Identity $DisPrimarysmtpaddress | Set-DistributionGroup -Name $Dis.NewName
}

Open in new window


Will.
0
 
JCJohnson76Author Commented:
My boss do not want to change the samaccountname only the displayname, alias, email field, and primartsmtpaddress field
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Will SzymkowskiSenior Solution ArchitectCommented:
Ok that is fine.

All you need to do is make sure that all of the fields are populated in your csv file DisplayName, Alias, primarysmtpaddress etc.

You then use the current smptaddress column in the csv to call each Distribution Group and change it to what you have in your csv file.

The script that i have provided only changes the Name of the Distribution Group, nothing else.

Will.
0
 
JCJohnson76Author Commented:
did not work; no errors in ISE; it only just echo my commands back on the powershell screen
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Copy the script to notepad save the file as .ps1 extension. Run this script from Exchange Management Shell.

I have just verified this script in my lab and it works as expected.

Also check your Distribution Groups and see if they actually did get modified.

Will.
0
 
JCJohnson76Author Commented:
can you provide an update of your syntax that changes that reflect my columns   Here is how my csv file looks <"NewName"Column1>   <"PrimarySMTPAddress" Column2> <"Alias" Column3> <"Displayname" Column4>

When I use your script it screwed up the account making not accessible

Goal to Change the display name, Alias,
0
 
JCJohnson76Author Commented:
Sorry to mention also the email field
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
You will also need to add a column for OldPrimarySMTP Address. to call the Distribution Groups you want to modify.

Once you have done that use the following script below...
$DisLists = Import-csv c:\filename.csv
ForEach ($Dis in $DisLists) {
$Dis.Oldsmtpaddress
$Dis.Alias
$Dis.Primarysmtpaddress
$Dis.NewName
$Dis.DisplayName
Get-DistributionGroup -Identity $DisOldsmtpaddress | Set-DistributionGroup -Name $Dis.NewName -PrimarySMTPAddress $Dis.Primarysmtpaddress -Alias $Dis.Alias -DisplayName $Dis.DisplayName
}

Open in new window


As a side note, ALWAYS make sure that you test this script before running it in production. As i have stated i had tested this in my lab environment but you will also need to test as well to ensure it will also run in your environment as well.

Will.
0
 
JCJohnson76Author Commented:
Always performed testing inside of my lab before doing in production.
0
 
JCJohnson76Author Commented:
Forgot to mention I do not want to change the old smtp address; if possible like to add another smtp address from different domain like @domain.com

thanks for your outstanding communication
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Ok so then instead of OldSMTPAddress Column you will need a column for the additional SMTP addresss example AdditionalSMTP. Final script will look like below...

CSV construct should look like
Primarysmtpaddress Alias  DisplayName   NewName  AdditionalSMTP
dis1.domain.com            dis1   dis1                   dis1             dis1@differentdomain.com
etc...

$DisLists = Import-csv c:\filename.csv
ForEach ($Dis in $DisLists) {
$Dis.Primarysmtpaddress
$Dis.Alias
$Dis.DisplayName
$Dis.NewName
$Dis.AdditionalSMTP
Get-DistributionGroup -Identity $Primarysmtpaddress | Set-DistributionGroup -Name $Dis.NewName -EmailAddresses $Dis.AdditionalSMTP -Alias $Dis.Alias -DisplayName $Dis.DisplayName -EmailAddressPolicyEnabled $false
}

Open in new window


That should do it.

Will.
0
 
JCJohnson76Author Commented:
Running this script removes my current smtp address and it also does not add the additional smtp address.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
If that is the case then you are not doing something right.

As you can see in the script it calls the Distribution Group by its PrimarySMTP address and then modifies the rest of the settings based on your CSV file. -EmailAddresses is used because this is how you add an additional SMTP address to the distribution group.

I also used the -EmailAddressPolicyEnabled $false because you will not be able to change this address if it is enabled.

Will.
0
 
JCJohnson76Author Commented:
we work on it again when get home from work today
0
 
JCJohnson76Author Commented:
Thanks
for all your support; and placing me on the right path
0
 
JCJohnson76Author Commented:
This script below that you posted does not modify the oldsmtpaddress but rather creates a new object.  But if you just insert one row of data inside of the csv it works.  Meaning if I insert multiple rows inside the csv it creates duplicate accounts.   Can you test on your side and insert mulitple rows inside your csv and not just one row data inside of the csv

$DisLists = Import-csv c:\filename.csv
ForEach ($Dis in $DisLists) {
$Dis.Oldsmtpaddress
$Dis.Alias
$Dis.Primarysmtpaddress
$Dis.NewName
$Dis.DisplayName
Get-DistributionGroup -Identity $DisOldsmtpaddress | Set-DistributionGroup -Name $Dis.NewName -PrimarySMTPAddress $Dis.Primarysmtpaddress -Alias $Dis.Alias -DisplayName $Dis.DisplayName
}

Thanks
1
 
JCJohnson76Author Commented:
found the issue;

Get-DistributionGroup -Identity $DisOldsmtpaddress  

Your previous script was missing the .  you have it correct in your recent one just sent.   Suppose to $dis.oldsmptaddress.


Thanks For all your help.
0
 
JCJohnson76Author Commented:
outstanding patient and communication
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Excellent,

Glad this is working for you now!

Will.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.