[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5041
  • Last Modified:

Exporting legacydn - importing X500 address

Hi Guys,
I'm not a scripting guy so I hope you can help me out with my task.
We are performing migration of 1000 mailboxes from Datacenter A to Datacenter B.
Each DC is with Exchange 2010SP3.

Problem is that I need to lookup for each account own LegacyDN in the first Active Directory and add it to the new account as X500 address.

If either of you can help me with this it will be great.
Basically, I need to have a script that export all the legacyDN of users based on their smtp address (Alias won't work, there are multiple users with the same alias) from the first site, and another script (or command) that will allow me to create X500 addresses to the same users on the new site using the output from the first script.

So, any help here will be very much appreciated.
Thanks.
0
webox_suuport
Asked:
webox_suuport
  • 5
  • 3
1 Solution
 
Tej Pratap Shukla ~DexterCommented:
Hey there
I took help from few internet sources to guide you through this problem, so here’s the powershell script you needed. To export user information from legacy DN execute the following Powershell script
Get-Mailbox -resultsize unlimited | Select-Object displayname -expandproperty emailaddresses | Where-Object {$_.smtpaddress -like "*domain.com*"} | Select-Object displayName,SmtpAddress | Export-csv "C:\details.csv"
We have now updated the details in a csv file named as details.csv. To create X500 addresses you need to execute the following command
$PrevCSV=Import-CSV c:\ details.csv
ForEach($Line in $PrevCSV)
{
$ProxyAddresses=$Line.EmailAddresses -split ";"
$X500Address="X500:"+"$($Line.LegacyExchangeDN)"
$ProxyAddresses+=$X500Address
Set-DistributionGroup -Identity $Line.Name  -EmailAddresses $ProxyAddresses
}
These commands should do the work as per your expectations. Feel free to ask for further queries
Thanks
~Dex
0
 
webox_suuportAuthor Commented:
Hi Dex,
First of all, thanks a lot.
The first part worked for me, but the I'm having problems with the second part.
I've copied the text to ps1 script and tried to execute it, but got the following error:

[PS] C:\>.\x500.ps1
Import-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "details.csv" to type "System.Char". Error: "String must be exactly one character long."
At C:\x500.ps1:1 char:20
+ $PrevCSV=Import-CSV <<<<  c:\ details.csv
    + CategoryInfo          : InvalidArgument: (:) [Import-Csv], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ImportCsvCommand

Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-DistributionGroup], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-DistributionGroup

Open in new window


If I'm trying to execute it manually, it ends:
[PS] C:\>ForEach($Line in $PrevCSV)
>> {
>> $ProxyAddresses=$Line.EmailAddresses -split ";"
>> $X500Address="X500:"+"$($Line.LegacyExchangeDN)"
>> $ProxyAddresses+=$X500Address
>> Set-DistributionGroup -Identity $Line.Name  -EmailAddresses $ProxyAddresses
>> }
>>

Open in new window


Probably doing it the wrong way... :-)
0
 
webox_suuportAuthor Commented:
Hmmm...
Guys? Some assistance here?
I need to migrate on Monday an organization of 250 mailboxes and I'm really really not into editing each account manually.

Edit:
It turns out that the first part is not so good, it does export the email addresses based on the domain, but not exporting the corresponding legacyExchangeDN attribute.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tej Pratap Shukla ~DexterCommented:
Hey
Try enclosing the path in quotes eg.
Import-CSV 'c:\ details.csv'
0
 
webox_suuportAuthor Commented:
Hi,
Well I managed to export the details using the following command:
Get-Mailbox -Filter {Emailaddresses -like "*domain.com*"} |select name,displayname,PrimarySmtpAddress,LegacyExchangeDN |Export-Csv "C:\details.csv"

Open in new window


Second part - I have tried to execute your script, but although it completed without any errors, the X500 address wasn't created.
0
 
Tej Pratap Shukla ~DexterCommented:
Hey
Well the command should have created x500 addresses, as the script executed successfully.Apparently I don't have access to a machine so cannot assist you regarding this issue, still you can try out another script.

"Import-CSV c:\details.csv | foreach{Set-ADuser -identity $_.user -add @{proxyAddresses = "X500:/o=mex05/ou=Exchange Administrative Group/cn=Recipients/cn=$($_.legacy)"}}"

Please revert back as soon as possible.

Thanks
~Dex
0
 
webox_suuportAuthor Commented:
Hi,
Attaching here is example of the csv that I have.
Running your command fails with Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null.
Since I don't have field identity on the csv.

Another point, I can see that your command is adding the X500 with different address that I have.
details.csv
0
 
Jamie McKillopCommented:
Hello,

The following script will do what you want:

Import-Csv C:\details.csv | % {
	$ProxyAddresses = (Get-Mailbox $_.primarysmtpaddress).emailaddresses
	$ProxyAddresses += [Microsoft.Exchange.Data.CustomProxyAddress]("X500:$($_.LegacyExchangeDN)")
	Set-Mailbox $_.primarysmtpaddress -EmailAddresses $ProxyAddresses
}

Open in new window


-JJ
0
 
webox_suuportAuthor Commented:
You Rock!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now