Link to home
Start Free TrialLog in
Avatar of webox_suuport
webox_suuport

asked on

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.
Avatar of Tej Pratap Shukla ~Dexter
Tej Pratap Shukla ~Dexter
Flag of India image

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
Avatar of webox_suuport
webox_suuport

ASKER

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... :-)
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.
Hey
Try enclosing the path in quotes eg.
Import-CSV 'c:\ details.csv'
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.
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
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
ASKER CERTIFIED SOLUTION
Avatar of Jamie McKillop
Jamie McKillop
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
You Rock!!