Skip to main content
All CollectionsMigratePowerShellCopy teams
Create a new Teams folder for migrations with PowerShell
Create a new Teams folder for migrations with PowerShell
Updated this week

With this guide, you can provision a new folder in the Files tab of your Teams General channel before running your migration script.

Index

Prerequisites

  • You have global admin or SharePoint admin permissions.

  • You are connected to your Microsoft 365 admin center in Explorer.

  • Your Teams have been provisioned.

Note: You must be site collection admin on each Team site, even if you have higher admin privileges. Your script includes the Add-SiteCollectionAdministrator command to apply the site collection admin permissions needed to create each folder. The added permissions are then removed using the Remove-SiteCollectionAdministrator command.

Script preparation

Create a folder on your local drive and a CSV list of all your Teams sites with the following steps:

  1. On your local drive, create a new folder.

  2. Name the folder as per your preference in your Teams General folder (e.g., C:\Migrated data).
    Note the path of the folder.

  3. In ShareGate Migrate, go to All reports from the sidebar.

  4. Click Create custom report in the top right corner.

  5. Select Microsoft 365 group as the object type.

  6. In Filters, select Is team connected Is Yes.

  7. In Columns, add Associated site address to the Selected Columns list.

  8. Click Continue without saving.

  9. Select your tenant, then click Next.

  10. Click Run now.

  11. Select the checkbox at the top of the list to select all of the Teams included in the report.

  12. Click Export in the top right corner.

  13. Save and open the file in Excel and do the following:

    • Delete the Display name, Email address, and Is team connected columns.

    • Rename the Associated site address column as SITEURL.

  14. Save this file as a CSV on your local drive (e.g., C:\foldermigration.csv).
    Note the path of the CSV file.

Create your script

$csvFile = "C:\foldermigration.csv"$table = Import-Csv $csvFile -Delimiter ","$MyPassword = ConvertTo-SecureString 'My password' -AsPlainText -Force$MyUsername = "My username"Set-Variable dstSite, dstListforeach ($row in $table) {    Clear-Variable dstSite    Clear-Variable dstList    $dstSite = Connect-Site -Url $row.SITEURL -UserName $MyUsername -Password $MyPassword    Add-SiteCollectionAdministrator -Site $site    $dstList = Get-List -Name Documents -Site $dstSite    Import-Document -SourceFilePath "C:\Migrated data" -DestinationList $dstList -DestinationFolder "General"    Remove-SiteCollectionAdministrator -Site $dstSite}

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

  • $csvFile: Adjust the path to point to the CSV file you saved before.

  • $table: The delimiter is the symbol that separates items in a row in your CSV. Ensure your script uses the same delimiter as your file (a quick way to verify this is by opening the CSV with Notepad).

  • $MyPassword and $MyUsername: Replace 'My password' and "My username" with your Microsoft 365 credentials.

  • Connect-site: The command to connect to a SharePoint site. If you need to change the authentication method, see Connect Site. To use Browser authentication, see Use credentials from a previous browser connection.

  • Set-Variable and Clear-Variable: These commands help prevent an issue where a connection failure can prevent your folder from being copied.

  • foreach: We use foreach to loop through the values in your CSV file. You can find more about it here.

  • -SourceFilePath: Replace "C:\Migrated data" with the folder path you created in step (2).

  • Add-SiteCollectionAdministrator: Add your user account as site collection administrator before migration. For more information, see Add Site Collection Administrator.

  • Remove-SiteCollectionAdministrator: Remove your user account as site collection administrator after migration. For more information, see Remove Site Collection Administrator.

Run your script after it is properly adjusted and tested.

Did this answer your question?