Skip to main content
All CollectionsMigratePowerShellUser and group mapping
Create a user mapping from a CSV file
Create a user mapping from a CSV file
Updated this week

Use PowerShell to generate a ShareGate Migrate user mapping file (.sgum) from a CSV document. You can use the user mapping file for your migrations in the application or in PowerShell.

Note: The application will map your users automatically. Any users you do not add in your mapping file will be mapped by ShareGate Migrate.

Index

Prerequisites

  • Access to your users' information, or your Active Directory.

Create your CSV

You can create the CSV manually, or get a list of users from your Active Directory. You will need a final CSV file with two columns named SourceValue and DestinationValue. You can use email, username, display name, or full name.

The file should look like this in Excel:

Tip: We recommend using email addresses as they are usually unique and include the domain.

Create your script

Copy and paste the following script in the PowerShell application of your choice.

Import-Module Sharegate
$csvFile = "C:\CSVfile.csv"
$table = Import-CSV $csvFile -Delimiter ","
$mappingSettings = New-MappingSettingsforeach ($row in $table) {    $results = Set-UserAndGroupMapping -MappingSettings $mappingSettings -Source $row.SourceValue -Destination $row.DestinationValue    $row.sourcevalue}Export-UserAndGroupMapping -MappingSettings $mappingSettings -Path "C:\FolderName\FileName"

Adjust your script so that it will work for you. Here are a few guidelines:

  • $csvFile: Adjust the path so the script calls your CSV file.

  • $table: The delimiter is the symbol your CSV uses to separate your column items. Make sure your script uses the same delimiter as your file (a quick way to verify this, is by opening the CSV with Notepad).

  • foreach: Loops through the values in your CSV file. You can find more about it here.

  • $results: The results are stored in a results variable instead of getting printed in your PowerShell window to avoid performance issues.

  • $row.sourcevalue: Prints the source value, so you can track your progress.

  • Export-UserAndGroupMapping: Adjust the path to save the new ShareGate Migrate user mapping file (SGUM) to your desired location with the name of your choice.

Using the SGUM file

You can import the SGUM file in a migration script with the following line:

$mappingSettings = Import-UserAndGroupMapping -Path "C:\FolderName\FileName.sgum​​"

Then, you can call the mapping on your Copy line (it will work with all the copy options such as Copy-Site and Copy-Content). Add the following on the same line as your copy command:

-MappingSettings $mappingSettings

You can also Import the SGUM file with the ShareGate Migrate migration option in Copy by clicking the Import button in the Map users and groups menu.

Did this answer your question?