Knowledge Base

How to generate a CSV file with PowerShell for CodeTwo migration tools

Problem:

You would like to prepare a CSV file using PowerShell for importing matched source and target mailbox pairs into CodeTwo migration tools.

Solution:

To generate a CSV file containing the information required for mailbox migration, download, configure and run one of the provided PowerShell scripts that best suits your migration scenario. Before you run any of the scripts, make sure that your target environment contains target mailboxes with identical display names as the source mailboxes you are planning to migrate.

CSV file structure

The CSV file must contain the following data:

CodeTwo data fieldOffice 365 propertyOn-premises Exchange property
Source mailbox email addressUserPrincipalNameUserPrincipalName
Source mailbox IDExternalDirectoryObjectIdExchangeGuid
Target mailbox email addressUserPrincipalNamePrimarySmtpAddress
Target mailbox IDExternalDirectoryObjectIdExchangeGuid

Additionally, the CSV may contain the following information as well:

CodeTwo data fieldOffice 365 propertyOn-premises Exchange property
Source mailbox first nameFirstNameFirstName
Source mailbox last nameLastNameLastName
Target mailbox email addressDisplayNameDisplayName

Our program will also recognize column headings if they are used in the file, and CSV files generated using our scripts will contain such headings. To learn more about using a CSV file for migration, read the appropriate sections in the CodeTwo Office 365 Migration user’s manual or the CodeTwo Exchange Migration user’s manual.

PowerShell scripts for generating a CSV file for migration

PowerShell scripts are available for the following migration scenarios:

Before you run a script, it must be configured. The details are provided individually for each of the scripts.

Migration between Microsoft 365 (Exchange Online) tenants

This script will generate a CSV file containing the following fields: Source email address, Source ID, First Name, Last Name, Display Name, Target email address, Target ID.

Download script

To use the script, open it in a text editor, such as Notepad, and enter the following information in the configuration of script section:

  • $SourceUPN – User Principal Name of the account you are going to use to sign in to the source server.
  • $TargetUPN – User Principal Name of the account you are going to use to sign in to the target server.
  • $ItemsPerFile – the maximum number of rows (entries) in the generated CSV file.

Users used to sign in to Exchange Online must be members of the Organization Management role group.

When this information is entered, save changes to the script and close the editor. You can now run the script.

Migration from Exchange Online (Microsoft 365) to on-premises Exchange

This script will generate a CSV file containing the following fields: Source email address, Source ID, First Name, Last Name, Display Name, Target email address, Target ID.

Download script

To use the script, open it in a text editor, such as Notepad, and enter the following information in the configuration of script section:

  • $SourceUPN – User Principal Name of the account you are going to use to sign in to the source server.
  • $TargetUri – target Exchange server uri.
  • $TargetAuthentication – target server authentication method, Basic or Kerberos.
  • $ItemsPerFile – the maximum number of rows (entries) in the generated CSV file.

Users used to sign in to Exchange Online and on-premises Exchange must be members of the Organization Management role group.

When this information is entered, save changes to the script and close the editor. You can now run the script.

Migration from on-premises Exchange to Exchange Online (Microsoft 365)

Use one of the scripts provided below to generate a CSV file containing the fields that you require.

Download script 1

(this script will create a CSV file containing the following fields: Source email address, Source ID, First Name, Last Name, Display Name, Target email address, Target ID)

Download script 2

(this script will create a CSV file containing the following fields: Source email address, Source ID, Display Name, Target email address, Target ID)

To use the script, open it in a text editor, such as Notepad, and enter the following information in the configuration of script section:

  • $SourceUri – source Exchange server uri.
  • $SourceAuthentication – source server authentication method, Basic or Kerberos.
  • $TargetUPN – User Principal Name of the account you are going to use to sign in to the target server.
  • $ItemsPerFile – the maximum number of rows (entries) in the generated CSV file.

Users used to sign in to on-premises Exchange and Exchange Online must be members of the Organization Management role group.

When this information is entered, save changes to the script and close the editor. You can now run the script.

Migration between on-premises Exchange servers

Use one of the scripts provided below to generate a CSV file containing the fields that you require.

Download script 1

(this script will create a CSV file containing the following fields: Source email address, Source ID, First Name, Last Name, Display Name, Target email address, Target ID)

Download script 2

(this script will create a CSV file containing the following fields: Source email address, Source ID, Display Name, Target email address, Target ID)

To use the script, open it in a text editor, such as Notepad, and enter the following information in the configuration of script section:

  • $SourceUri – source Exchange server uri.
  • $SourceAuthentication – source server authentication method, Basic or Kerberos.
  • $TargetUri – target Exchange server uri.
  • $TargetAuthentication – target server authentication method, Basic or Kerberos.
  • $ItemsPerFile – the maximum number of rows (entries) in the generated CSV file.

Users used to sign in to on-premises Exchange must be members of the Organization Management role group.

When this information is entered, save changes to the script and close the editor. You can now run the script.

How to run a PowerShell script

Follow the instructions below to run a PowerShell script that will generate a CSV file containing the source and target mailbox information required for successful migration:

  1. Download a PowerShell script file.
  2. Open the script in a text editor, such as Notepad.
  3. Find the section of the script that starts with:
# =================== configuration of script ===============================
  1. Enter the required information in this section of the script, save changes and close the editor. Details regarding the information required by each of the scripts are provided in their descriptions above.
  2. Run ps PowerShell.
  3. In PowerShell, navigate to the folder where the script is located.
  4. Type .\ and press Tab until the name of your script is displayed and press Enter to run it.
  5. The output CSV file will be saved in the same folder as the script.

The generated CSV file will look similar to the one shown in Fig. 1.

A CSV file opened in Microsoft Excel.
Fig.1. A CSV file generated using one of the scripts provided in this article.