Skip to main content
All CollectionsMigratePowerShellPowerShell Tips and tricks
Add site collections to the Explore screen in PowerShell
Add site collections to the Explore screen in PowerShell
Updated over a month ago

You can add individual site collections one at a time in the Explore screen or all the site collections from your farm or tenant by connecting to your admin center or central admin.

To connect to several specific site collections in the Explorer without having to do each connection individually, use the -AddToExplorer parameter in a PowerShell script.

Tip: You can also export and import your connections from Explorer to share them with other ShareGate Migrate users.

Add a single site collection to the Explore screen

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

# Import the Sharegate module
Import-Module Sharegate

# Define user credentials
$myUsername = "myusername"
$myPassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force

# Connect to the SharePoint site and add it to File Explorer
Connect-Site -Url "http://yourtenant.sharepoint.com/sites/yoursitecollection" -Username $myUsername -Password $myPassword -AddToExplorer

Adjust your script to make it work for you. Here are a few guidelines:

  • $myUsername and $myPassword: Replace "myusername" and 'mypassword' with your SharePoint or Microsoft 365 credentials.

  • Connect-Site: If you need to change the authentication method, you will find how to do it in the Connect Site article.

  • -URL: Replace the URL to match your site collection's URL.

Run your script when it's properly adjusted and tested.

Tip: With this script, you can have multiple Connect-Site lines with different URLs to add multiple Site Collections to Explorer. If you have a lot of sites to connect to, we suggest using the CSV method below instead.

Add multiple site collections to the Explorer using a CSV

Create a CSV guide for your connections

  1. Create a new Excel document.

  2. Name the first column URL.

  3. List the URLs of all the site collections you want to add to the Explorer.

    mceclip0.png
  4. Save the file as a CSV.

Create your script

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

# Import the Sharegate module
Import-Module Sharegate

# Define the path to the CSV file
$csvFile = "C:\CSVfile.csv"

# Import the CSV file into a table (array of objects)
$table = Import-Csv $csvFile

# Define user credentials
$myUsername = "myusername"
$myPassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force

# Loop through each row in the CSV table and connect to the specified SharePoint site
foreach ($row in $table) {
Connect-Site -Url $row.URL -Username $myUsername -Password $myPassword -AddToExplorer
}

Adjust your script to make it work for you. Here are a few guidelines:

  • $csvFile: Adjust the path so that it points to the CSV file you saved before.

  • $myUsername and $myPassword: Replace "myusername" and 'mypassword' with your SharePoint or Microsoft 365 credentials.

  • Connect-site: If you need to change the authentication method, you will find how to do it in the Connect Site article.

  • foreach: Loops the commands between the brackets for each row in your CSV file. In this case, it adds your connections to the Explorer in ShareGate Migrate.

Run your script when it's properly adjusted and tested.

Did this answer your question?