Skip to main content

Connect-Site

Connect to a SharePoint site with PowerShell

Updated over 3 weeks ago

Command

Connect-Site

Description

The command to connect to a SharePoint site.

Notes:

ShareGate Migrate displays an error message on the PowerShell command line if you use an invalid URL.

-ModernAuth only works on SharePoint sites and OneDrive for Business.

At the end of January 2026, Microsoft began deprecating the IDCRL cookie, meaning that only Browser and Modern authentication methods with the parameters -Browser and -ModernAuth will work in most Microsoft 365 tenants.

Note: As of the end of January 2026, Microsoft began deprecating the IDCRL cookie, meaning that only Browser and Modern authentication methods with the parameters -Browser and -ModernAuth will work in most Microsoft 365 tenants. To learn more about this change, see Important change to "Other user" authentication for Microsoft 365.

Examples

Connect to the SharePoint Online site using Modern Authentication in Microsoft 365

$mysite = Connect-Site -Url http://mytenantdomain/sites/mysitecollection -ModernAuth

Connect to the SharePoint Online site using Modern Authentication with UserName in Microsoft 365

$mysite = Connect-Site -Url http://mytenantdomain/sites/mysitecollection -ModernAuth -UserName [email protected]

Note: You will get prompted to enter your password in the PowerShell window.

Connect to the SharePoint Online site using Modern Authentication with UserName and password in Microsoft 365

$mypassword = ConvertTo-SecureString "mypassword" -AsPlainText -Force
$mysite = Connect-Site -Url http://mytenantdomain/sites/mysitecollection -ModernAuth -UserName [email protected] -Password $mypassword

Connect to the SharePoint site with the current user credentials

Connect-Site -Url "http://myfarm1/sites/mysitecollection"

Connect to the SharePoint site with a username

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Username "myusername"

Connect to the SharePoint site with username and password

$mypassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force

$mysite = Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Username "myusername" -Password $mypassword

Connect to the SharePoint site without single sign-on (SSO)

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Browser -DisableSSO

Connect to the SharePoint site with proxy settings

$proxySettings = New-ProxySettings -Server myproxyserver -Port 888

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -ProxySettings $proxySettings

Connect to the SharePoint site using Browser Authentication

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Browser

Note: To avoid entering your credentials multiple times when you use a foreach loop, see Use credentials from a previous browser connection.

Connect to the SharePoint site using Browser Authentication with proxy settings

$proxySettings = New-ProxySettings -Server myproxyserver -Port 888

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Browser -ProxySettings $proxySettings

Connect to the SharePoint site using existing connection credentials

$connection = Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Browser

Connect-Site -Url "http://myfarm1/sites/anothersitecollection" -UseCredentialsFrom $connection

Connect to the SharePoint site using existing connection credentials

$connection = Connect-Tenant -Domain "mytenantdomain" -Browser

Connect-Site -Url "http://mytenantdomain/sites/mysitecollection" -UseCredentialsFrom $connection

Connect and add the SharePoint site connection to the ShareGate Migrate Explorer

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -AddToExplorer

Connect to the SharePoint site using a prompt to enter your username and password

$Credentials = Get-Credential

Connect-Site -Url "http://myfarm1/sites/mysitecollection" -Credential $Credentials

Note: Get-Credential is a Microsoft PowerShell command. When you use it in your script, it opens a prompt on your workstation to enter your credentials and store them in a variable.

Syntax

Connect-Site
-Url <String>
[-AllowConnectionFallback <SwitchParameter>]
[-ProxySettings <ProxySettings>]
[-AddToExplorer <SwitchParameter>]
-UserName <String> -Password <SecureString>
-ModernAuth <SwitchParameter>
Connect-Site
-Url <String>
-Credential <PSCredential>
[-AllowConnectionFallback <SwitchParameter>]
[-ProxySettings <ProxySettings>]
[-AddToExplorer <SwitchParameter>]
-UserName <String>
-Password <SecureString>
-ModernAuth <SwitchParameter>
Connect-Site
-Url <String>
-UseCredentialsFrom <ConnectionEntity>
[-AllowConnectionFallback <SwitchParameter>]
[-AddToExplorer <SwitchParameter>]
-UserName <String>
-Password <SecureString>
-ModernAuth <SwitchParameter>
Connect-Site
-Url <String>
-Browser <SwitchParameter>
[-AllowConnectionFallback <SwitchParameter>]
[-DisableSSO <SwitchParameter>]
[-ProxySettings <ProxySettings>]
[-AddToExplorer <SwitchParameter>]
-UserName <String>
-Password <SecureString>
-ModernAuth <SwitchParameter>
Connect-Site
-Url <String>
-UserName <String>
-Password <SecureString>
[-AllowConnectionFallback <SwitchParameter>]
[-ProxySettings <ProxySettings>]
[-AddToExplorer <SwitchParameter>]
-ModernAuth <SwitchParameter>
Connect-Site
-Url <String>
-UserName <String>
-Password <SecureString>
-ModernAuth <SwitchParameter>
[-AllowConnectionFallback <SwitchParameter>]
Connect-Site
-Url <String>
-ModernAuth <SwitchParameter>
[-AllowConnectionFallback <SwitchParameter>]
-UserName <String>
-Password <SecureString>

Parameters

-AddToExplorer <SwitchParameter>

Adds the connection to the Sharegate Explorer.

Required?

False

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

(All)

Aliases

None

-AllowConnectionFallback <SwitchParameter>

Allows ShareGate to search for connections options by going up the hierarchy if it can't connect to the specified URL.

Required?

False

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

(All)

Aliases

None

-Browser <SwitchParameter>

Use browser authentication.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

Browser

Aliases

None

-Credential <PSCredential>

Specifies the credentials.

Required?

True

Default value

None

Accept pipeline input?

True (ByValue, ByPropertyName)

Accept wildcard characters?

False

Parameter set name

Credential

Aliases

None

-DisableSSO <SwitchParameter>

Disables the auto-login feature in order to connect to a Microsoft 365 site with another user account.

Required?

False

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

Browser

Aliases

None

-ModernAuth <SwitchParameter>

Use modern authentication.

Note: For now, -ModernAuth only works when connecting to SharePoint sites and OneDrive for Business. You will have to use -Browser to connect to other Microsoft 365 services, such as Teams or Exchange mailboxes.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

ModernManualAuth, ModernAuth

Aliases

None

-Password <SecureString>

Specifies the password. Use single quotation marks (') to pass the string to the command exactly as you type it.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

Manual

Aliases

None

-ProxySettings <ProxySettings>

Sets the proxy settings to connect to the SharePoint site.

Required?

False

Default value

None

Accept pipeline input?

True (ByValue, ByPropertyName)

Accept wildcard characters?

False

Parameter set name

Default, Credential, Manual, Browser

Aliases

None

-Url <String>

Sets the URL of the SharePoint site.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

(All)

Aliases

None

-UseCredentialsFrom <ConnectionEntity>

Use credentials from another connection.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

UseCredentialsFrom

Aliases

None

-UserName <String>

Specifies the username.

Required?

True

Default value

None

Accept pipeline input?

False

Accept wildcard characters?

False

Parameter set name

Manual

Aliases

None

Did this answer your question?