Getting started with ShareGate’s PowerShell module for Microsoft 365 migrations 

Sgpower Featured

ShareGate Migrate handles large-scale migrations without the need for scripting, while our PowerShell module offers powerful cmdlets for those who prefer a more hands-on approach. Learn how to leverage flexible automation to streamline your big Microsoft 365 migration.

When you’re managing IT systems, there’s always more to do than time to do it. That’s why tools like ShareGate’s PowerShell module are a game-changer. Designed specifically for IT pros, this module helps you automate repetitive tasks, scale migrations, and handle complex projects with ease—all while integrating seamlessly with the ShareGate UI.

And the best part? You don’t need to be a PowerShell wizard to get started. 

In this guide, we’ll show you how to use ShareGate’s PowerShell module to simplify your Microsoft 365 migration. We’ll cover everything from setting up the module to practical examples of batch migrations. Whether you’re new to PowerShell or a seasoned pro, there’s something here for you. 


What is ShareGate’s PowerShell module? 

ShareGate’s PowerShell module is your key to faster, more efficient workflows. As a powerful extension of our end-to-end cloud migration solution, it puts flexible automation at your fingertips by enabling you to execute tasks in ShareGate using PowerShell commands, called cmdlets. These commands are perfect for handling bulk actions and repetitive processes, especially during Microsoft 365 migrations. 

Nearly all of ShareGate’s migration features can be accessed through the module, making it a versatile alternative for managing larger scopes or batch migrations. Whether you prefer a script-based approach or need to tackle repetitive tasks, the PowerShell module lets you customize workflows to your unique needs, transforming the way your IT team works. Instead of spending hours — or even days — on manual processes, you can easily create straightforward scripts that do the heavy lifting for you. It’s all about working smarter, not harder! 

Requirements 

To use ShareGate’s PowerShell module, you’ll need: 

  • Windows PowerShell 3.0 or higher 
  • A ShareGate license 

Note: PowerShell 7.1 isn’t supported yet because it relies on .NET Core but rest assured: compatibility is on ShareGate’s product roadmap

Key features of the PowerShell module 

The ShareGate PowerShell module is packed with cmdlets designed to simplify and automate complex tasks in Microsoft 365 and SharePoint environments. From migrating data to managing settings and permissions, these capabilities save time and effort, especially when dealing with large-scale or repetitive processes.  

Here’s a closer look at what you can do with it: 

  1. Automated migrations: Need to move content, sites, or permissions? ShareGate’s PowerShell module has you covered with flexible copy options that make the process fast and efficient. You can also run incremental migrations to capture the latest changes or schedule migrations to run at specific times — such as during off-hours — to minimize throttling and ensure a smoother experience.  
  2. Manage settings at scale: With ShareGate’s PowerShell module, you can automate tasks like adding site collection administrator rights in SharePoint or provisioning OneDrive for Business accounts in bulk. This saves time, ensures consistency, and simplifies managing large-scale changes. 
  3. Copy mailboxes: With ShareGate’s PowerShell module, you can sequence and customize mailbox migrations.
  4. Copy teams and channels: Moving Microsoft Teams content? Use ShareGate’s PowerShell module to migrate teams and move channels across Microsoft 365 tenants. It’s a seamless solution for handling even large-scale Teams migrations efficiently. 

Automate your Microsoft administration: Check out 5 PowerShell script examples


How to set up ShareGate’s PowerShell module 

Getting started with ShareGate’s PowerShell module is easy. Here’s how: 

Step 1: Launch PowerShell 

You can access ShareGate’s PowerShell module in two ways: 

1. From the ShareGate UI: ShareGate’s PowerShell commands are ready to use straight out of the box when you launch PowerShell directly from ShareGate Migrate. Just click the PowerShell button in the bottom-left corner of the screen to open a pre-configured session, making it quick and easy to get started. 

Sharegate Powershell Module

2. Manually import the module: To start using the ShareGate PowerShell module in any other PowerShell environment (i.e., if you prefer to use Windows PowerShell or PowerShell ISE), you’ll need to import the ShareGate Migrate commands manually.  
 
Simply type the following code at the beginning of any script to import the command to your PowerShell app:

Import-Module Sharegate

Note: Before importing the module, make sure that you have ShareGate Migrate installed on your machine; otherwise, the ShareGate PowerShell commands won’t work. Check out our documentation for step-by-step installation instructions.

Step 2: Establish connections 

At the core of your PowerShell migrations, you’ll need to establish connections to your environments. Choosing the right authentication method ensures a smooth connection and sets the stage for running commands effectively.

ShareGate’s PowerShell module supports several authentication methods. Depending on your setup, we recommend the following: 

  • Modern authentication: Use the -Browser parameter to securely authenticate through a browser pop-up.  
    • Ideal (and strongly recommended) for SharePoint Online and required for environments with multi-factor authentication (MFA) enabled. This method provides enhanced security and aligns with Microsoft’s best practices. Learn more about browser authentication in our documentation. 

Tip: To avoid entering your credentials for every connection in a foreach loop statement, with browser authentication, you can use the PowerShell parameter -UseCredentialsFrom to create a single connection and reuse the credentials from that connection in your script. See our corresponding documentation to learn more. 

  • Legacy authentication: Use the -Username and -Password parameters to provide your credentials directly for basic authentication scenarios. 
    • Suitable for simpler scenarios where MFA is not required.

Whenever possible, modern authentication is recommended for a more secure and reliable connection, especially when working in SharePoint Online. For a full list of available authentication methods, head over to our documentation outlining how to connect to your Microsoft 365 tenant or SharePoint site with PowerShell. 

Best practices for authentication 

To streamline your workflow and avoid authentication issues when using ShareGate’s PowerShell module, keep these best practices in mind: 

  • Use -DisableSSO unless single sign-on is required: This gives you more control over authentication, particularly in environments where single sign-on might cause conflicts or unexpected behavior. 
  • Establish connections before running batch scripts: Always authenticate and confirm your connection before executing batch scripts to prevent interruptions during long or complex tasks. 
  • Use -UseCredentialsFrom for repetitive tasks: This parameter allows you to reuse stored credentials, avoiding repeated authentication prompts during recurring operations, saving you valuable time and simplifying workflows.  

Step 3: Run commands 

Once you’ve learned how to establish connections, you’re ready to start using the ShareGate PowerShell module. Whether you’re migrating content or exporting data, the module provides a variety of cmdlets to get the job done efficiently. Some of the basic commands that can be used to kick off migrations include:

Copy-Mailbox

Copy-Team

Copy-Site 

Copy-List 

Copy-ContentType 

Import-Document 

Import-GoogleDriveDocument 

Import-BoxDocument 

For a complete list of available cmdlets and their detailed usage, refer to the ShareGate documentation. With these tools at your disposal, you can customize scripts to fit your specific needs and streamline your workflows. 


Practical examples: Batch migrations with the ShareGate PowerShell module 

The ShareGate PowerShell module makes it easy to migrate data from a variety of sources, including file shares, Google Drive, and Box.com. But its real strength lies in its ability to automate batch migrations, saving you time and effort when handling large-scale projects. Here are a few common scenarios where the module truly shines: 

Example 1: File share to OneDrive migrations 

Migrating data from file shares to OneDrive can be complex, especially when managing large volumes of data or intricate permission structures. Fortunately, ShareGate’s PowerShell module simplifies the process by enabling automation and ensuring accuracy every step of the way. Here’s a high-level walkthrough of how it works: 

1. Prepare a CSV file  

Start by creating a CSV file that maps the source file share paths to their corresponding OneDrive destinations. This file will serve as the foundation of your PowerShell script, ensuring the migration process is properly structured and organized and enabling you to handle multiple migrations efficiently. 

You can generate a list of the names of all the directories included in the DOMAIN folder using this script (replace the paths with your own): 

dir -Directory Z:\ -Name | Out-File C:\MigrationPlanning\onedrivemigration.csv 

In the resulting CSV file, insert a new header row at the top and name the first column DIRECTORY. Name the second column ONEDRIVEURL and input the OneDrive URLs that correspond to the correct directory in your rows. (You can generate a list of all the OneDrives in your Microsoft 365 environment in just a few clicks by creating a custom report in ShareGate Migrate, then exporting it as a CSV.) 

Csvfile

The resulting CSV file should look similar to the one shown above. Once ready, save it to your drive. 

2. Define your migration plan 

Using the CSV file you prepared, create a custom PowerShell script to guide your migration process. Start by copying and pasting the following script in the PowerShell application of your choice:

Import-Module Sharegate 
 
# Define the CSV file path 
$csvFile = "C:\MigrationPlanning\onedrivemigration.csv" 
 
# Import the CSV file 
$table = Import-Csv $csvFile -Delimiter "," 
 
# Define the password for authentication 
$mypassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force 
 
# Set variables for site and list operations 
Set-Variable dstSite, dstList 
 
# Loop through each row in the CSV 
foreach ($row in $table) { 
  # Clear previous values of variables 
  Clear-Variable dstSite 
  Clear-Variable dstList 
 
  # Connect to the OneDrive site 
  $dstSite = Connect-Site -Url $row.ONEDRIVEURL -Username "myusername" -Password $mypassword 
 
  # Get the "Documents" list from the destination site 
  $dstList = Get-List -Name Documents -Site $dstSite 
 
  # Import documents from the source folder to the destination list 
  Import-Document -SourceFolder $row.DIRECTORY -DestinationList $dstList 
 
  # Remove site collection administrator permissions 
  Remove-SiteCollectionAdministrator -Site $dstSite 
}

Then adjust your script so that it will work for you, making sure to adjust the path so that it points to the CSV file you just saved, replacing ‘mypassword’ and ‘myusername’ with your Microsoft 365 admin account username and password, and adjusting your authentication method if needed.  

Tip: You can use a foreach loop statement (as seen in the script shown above) to copy to and from multiple locations listed in a CSV file. This allows you to establish a list of parameters like Site URLs, list names, List views, and more, to dictate the flow of your migration. This setup allows you to handle multiple migration paths in one go, making it easy to handle batch migrations. See ShareGate’s PowerShell documentation for more details. 

3. Automate data transfers 

Once it’s properly adjusted and tested, you can run your script. To transfer large data sets efficiently and minimize disruptions, you can also schedule your PowerShell migrations to run at set times, like during off-hours. This helps avoid throttling and ensures a smoother transfer process. 

4. Run incremental updates 

For environments where file shares are actively updated, you can use the module to run incremental migrations. This captures any new or modified files since the last migration, keeping your OneDrive destination up-to-date without duplicating data. 

5. Monitor and verify progress

ShareGate’s PowerShell module automatically generates migration reports to track the status of your migration. Review these reports (you’ll be able to find them in Tasks) to verify completion and quickly troubleshoot any issues that arise. You can also export the reports in your script with Export-Report

By automating some of your more repetitive migration tasks, the ShareGate PowerShell module transforms what could be a time-consuming and error-prone process into an efficient, streamlined operation. For a more detailed file share to OneDrive for Business walkthrough, check out this step-by-step guide

Example 2: Migrating site collections 

Migrating multiple site collections doesn’t have to be overwhelming. ShareGate’s PowerShell module simplifies the process with cmdlets like Copy-Site, enabling you to move entire site collections — along with their structure, lists, and content — between SharePoint environments. 

Here’s how the module can help: 

  • Transfer full site collections: Migrate sites with their associated lists, libraries, and permissions intact. 
  • Preserve site structure: Ensure navigation, subsites, and hierarchy are copied seamlessly. 
  • Customize migration settings: Configure options for metadata, document versions, and permissions to match your needs. 

For more details and step-by-step guidance on using the Copy-Site cmdlet, refer to ShareGate’s PowerShell documentation

Example 3: Content-only migrations 

When you need to migrate content without affecting the site structure, ShareGate’s PowerShell module provides a flexible and precise solution. The Copy-Content cmdlet allows you to: 

  • Target specific content: Migrate items, folders, or views from one SharePoint list or library to another. 
  • Preserve metadata and version history: Ensure documents retain their original metadata and versions for consistency. 
  • Streamline updates: Focus solely on moving the content you need without modifying the existing site layout. 

This approach is ideal for scenarios like updating libraries or consolidating content across environments. For comprehensive guidance and examples on using the Copy-Content cmdlet, refer to ShareGate’s official documentation.  


Don’t just migrate it, ShareGate it 

While PowerShell is incredibly flexible, ShareGate’s intuitive design and built-in automation features make it even easier to manage Microsoft 365.  

With ShareGate’s out-of-the-box Microsoft 365 migration and governance tool, you can: 

  • Simplify permissions management: Handle SharePoint and Teams permissions with ease. 
  • Migrate effortlessly: Perform migrations and copy content without the need for complex scripts. 
  • Automate reporting: Schedule reports to identify and resolve issues like inactive teams, orphaned sites, and insecure/unsecured external sharing. 
  • Save time: Focus on strategy while ShareGate streamlines your Microsoft 365 management and handles the heavy lifting. 

“I love writing PowerShell, but if ShareGate has a report or capability that gets me there instead, I can save all that time.”

Marc D. Anderson, Microsoft MVP

With ShareGate, you’re not just migrating — you’re transforming the way you manage Microsoft 365. Whether you’re handling batch migrations, managing permissions, or simplifying complex workflows, ShareGate empowers you to deliver better outcomes for your end users.  

Ready to see what ShareGate’s PowerShell module can do for you? Book a call with one of our experts for a personalized walkthrough of its features. 

What did you think of this article?

Recommended by our team

Your biggest Microsoft 365 jobs, made easy

15-day full-featured trial—no strings, no credit card.

Spot Icon

Smooth Google migration  Migrate from Google Drive to M365 the right way