Link to home
Start Free TrialLog in
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?
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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

ASKER

My boss do not want to change the samaccountname only the displayname, alias, email field, and primartsmtpaddress field
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.
did not work; no errors in ISE; it only just echo my commands back on the powershell screen
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.
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,
Sorry to mention also the email field
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.
Always performed testing inside of my lab before doing in production.
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
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.
Running this script removes my current smtp address and it also does not add the additional smtp address.
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.
we work on it again when get home from work today
Thanks
for all your support; and placing me on the right path
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
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
outstanding patient and communication
Excellent,

Glad this is working for you now!

Will.