Avatar of JCJohnson76
JCJohnson76
 asked on

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?
PowershellExchange

Avatar of undefined
Last Comment
Will Szymkowski

8/22/2022 - Mon
Will Szymkowski

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.
JCJohnson76

ASKER
My boss do not want to change the samaccountname only the displayname, alias, email field, and primartsmtpaddress field
Will Szymkowski

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
JCJohnson76

ASKER
did not work; no errors in ISE; it only just echo my commands back on the powershell screen
Will Szymkowski

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.
JCJohnson76

ASKER
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,
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
JCJohnson76

ASKER
Sorry to mention also the email field
Will Szymkowski

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.
JCJohnson76

ASKER
Always performed testing inside of my lab before doing in production.
Your help has saved me hundreds of hours of internet surfing.
fblack61
JCJohnson76

ASKER
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
Will Szymkowski

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.
JCJohnson76

ASKER
Running this script removes my current smtp address and it also does not add the additional smtp address.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Will Szymkowski

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.
JCJohnson76

ASKER
we work on it again when get home from work today
JCJohnson76

ASKER
Thanks
for all your support; and placing me on the right path
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
JCJohnson76

ASKER
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
ASKER CERTIFIED SOLUTION
Will Szymkowski

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
JCJohnson76

ASKER
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.
JCJohnson76

ASKER
outstanding patient and communication
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Will Szymkowski

Excellent,

Glad this is working for you now!

Will.