Connect-SPOService

将 SharePoint 管理员或 SharePoint Embedded 管理员连接到 SharePoint 管理中心。 必须先运行此 cmdlet,然后才能运行任何其他 SharePoint Online cmdlet。

语法

AuthenticationCertificate

Connect-SPOService
    [-Url] <UrlCmdletPipeBind>
    [[-ClientTag] <String>]
    -ClientId <String>
    -TenantId <String>
    [-Region <AADCrossTenantAuthenticationLocation>]
    [-AuthenticationUrl <String>]
    [-Certificate <X509Certificate2>]
    [-CertificatePath <String>]
    [-CertificateThumbprint <String>]
    [-CertificatePassword <SecureString>]
    [<CommonParameters>]

AuthenticationLocation

Connect-SPOService
    [-Url] <UrlCmdletPipeBind>
    [[-Credential] <CredentialCmdletPipeBind>]
    [[-ClientTag] <String>]
    [[-ModernAuth] <Boolean>]
    [[-UseSystemBrowser] <Boolean>]
    [-Region <AADCrossTenantAuthenticationLocation>]
    [<CommonParameters>]

AuthenticationManagedIdentity

Connect-SPOService
    -Url <UrlCmdletPipeBind>
    [-ClientTag <String>]
    [-ManagedIdentity]
    [-ManagedIdentityType <ManagedIdentityType>]
    [-ManagedIdentityClientId <String>]
    [<CommonParameters>]

AuthenticationUrl

Connect-SPOService
    [-Url] <UrlCmdletPipeBind>
    [[-Credential] <CredentialCmdletPipeBind>]
    [[-ClientTag] <String>]
    [[-ModernAuth] <Boolean>]
    [[-UseSystemBrowser] <Boolean>]
    -AuthenticationUrl <String>
    [<CommonParameters>]

说明

此 cmdlet 将 SharePoint 管理员或 SharePoint Embedded 管理员连接到 SharePoint 管理中心。 组织内每个 Windows PowerShell 会话和每个地理位置仅支持一个 SharePoint Online 服务连接。 如果再次运行此 cmdlet,现有连接将自动断开并替换为新连接。 然后,PowerShell 会话使用新指定的管理员上下文。 在同一 PowerShell 会话中管理多个组织时,委派的合作伙伴管理员必须切换连接。 要运行此 cmdlet,您必须是 SharePoint 管理员或 SharePoint Embedded 管理员。 有关权限要求和最新指南,请参阅 SharePoint Online 命令行管理程序简介文档。

示例

示例 1

Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential admin@contoso.com

此示例展示了使用帐户admin@contoso.com的 SharePoint 管理员如何连接到位于 的 SharePoint 管理中心。https://contoso-admin.sharepoint.com

示例 2

$username = "admin@contoso.sharepoint.com"
$password = Read-Host -Prompt "Enter user password" -AsSecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $password
Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential $cred

此示例演示 SharePoint 管理员如何通过从用户名和密码创建凭据对象连接到 SharePoint 管理中心 https://contoso-admin.sharepoint.com

示例 3

Connect-SPOService -Url https://contoso-admin.sharepoint.com

此示例提示输入凭据。 帐户使用多重身份验证时,需要使用此方法。

示例 4

Connect-SPOService -Url https://contoso-admin.sharepoint.com -Region ITAR

此示例通过指定身份验证区域连接到 SharePoint 管理中心。

示例 5

Connect-SPOService -Credential $creds -Url https://tenant-admin.sharepoint.com -ModernAuth $true -AuthenticationUrl https://login.microsoftonline.com/organizations

此示例使用新式身份验证连接到 SharePoint 管理中心。

示例 6

Connect-SPOService -Url https://contoso-admin.sharepoint.com -UseSystemBrowser $true

此示例使用 MSAL) (Microsoft身份验证库进行身份验证,并在身份验证成功后连接到 SharePoint 管理中心。

示例 7

$password = Read-Host -Prompt "Enter certificate password" -AsSecureString
Connect-SPOService -Url https://contoso-admin.sharepoint.com -ClientId 00000000-0000-0000-0000-000000000000 -TenantId 11111111-1111-1111-1111-111111111111 -CertificatePath C:\Certs\ContosoAppAuth.pfx -CertificatePassword $password

此示例使用应用标识和证书文件路径以及可选证书密码连接到 SharePoint 管理中心。

示例 8

Connect-SPOService -Url https://contoso-admin.sharepoint.com -ClientId 00000000-0000-0000-0000-000000000000 -TenantId 11111111-1111-1111-1111-111111111111 -CertificateThumbprint "3FAAAA1111AAAAAAAAAAA2222AAAAAAAAAAAAAAA"

此示例使用应用标识和证书指纹连接到 SharePoint 管理中心。

示例 9

$thumbprint = "3F2A5C9D4E7B8A1234567890ABCDEF1234567890"
$cert = Get-ChildItem Cert:\LocalMachine\My\$thumbprint
Connect-SPOService -Url https://contoso-admin.sharepoint.com -ClientId 00000000-0000-0000-0000-000000000000 -TenantId 11111111-1111-1111-1111-111111111111 -Certificate $cert

此示例使用应用标识和证书对象连接到 SharePoint 管理中心。

示例 10

Connect-SPOService -Url https://contoso-admin.sharepoint.com -ManagedIdentity

此示例使用系统分配的托管标识连接到 SharePoint 管理中心。

示例 11

Connect-SPOService -url https://contoso-admin.sharepoint.com -ManagedIdentity -ManagedIdentityType UserAssigned -ManagedIdentityClientId 00000000-0000-0000-0000-000000000000

此示例使用用户分配的托管标识连接到 SharePoint 管理中心。

参数

-AuthenticationUrl

适用:SharePoint Online

指定 Microsoft Entra 跨租户身份验证服务的 URL。 当需要非默认的跨租户身份验证终结点时使用此参数。

参数属性

类型:System.String
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationUrl
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Certificate

适用:SharePoint Online

指定用于身份验证的 X.509 证书。

参数属性

类型:X509Certificate2
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationCertificate
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-CertificatePassword

适用:SharePoint Online

指定证书文件的密码。

参数属性

类型:SecureString
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationCertificate
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-CertificatePath

适用:SharePoint Online

指定本地 .pfx 证书文件的路径。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationCertificate
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-CertificateThumbprint

适用:SharePoint Online

指定当前用户的证书存储中证书的指纹。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationCertificate
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ClientId

适用:SharePoint Online

指定应用程序的客户端 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False
别名:ApplicationId

参数集

AuthenticationCertificate
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ClientTag

适用:SharePoint Online

(可选)将客户端标记添加到 CSOM HTTP 流量,以帮助识别调用脚本或解决方案。

参数属性

类型:System.String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Credential

适用:SharePoint Online

指定用于连接的凭据。 如果未提供凭据,系统将提示您输入凭据。 凭据必须属于有权访问 SharePoint 管理中心的管理员。

参数属性

类型:Microsoft.Online.SharePoint.PowerShell.CredentialCmdletPipeBind
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationUrl
Position:Named
必需:False
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False
AuthenticationLocation
Position:Named
必需:False
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ManagedIdentity

适用:SharePoint Online

指示连接使用托管标识,而不是基于用户或证书的身份验证。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationManagedIdentity
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ManagedIdentityClientId

适用:SharePoint Online

指定要用于身份验证的用户分配的托管标识的客户端 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationManagedIdentity
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ManagedIdentityType

适用:SharePoint Online

指定身份验证时要使用的托管标识的类型。 如果未指定,则使用默认的托管标识类型。

参数属性

类型:ManagedIdentityType
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationManagedIdentity
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ModernAuth

适用:SharePoint Online

在连接到 SharePoint 管理 cmdlet 时启用新式身份验证。 使用此参数时,还必须指定该 AuthenticationUrl 参数。

参数属性

类型:System.Boolean
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationUrl
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
AuthenticationLocation
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Region

适用:SharePoint Online

指定身份验证区域。 有效值为:Default、、 ITARGermanyChina。 默认值为 Default注意:ITAR 值仅适用于 GCC High 和 DoD 租户。

参数属性

类型:Microsoft.Online.SharePoint.PowerShell.AADCrossTenantAuthenticationLocation
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationLocation
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
AuthenticationCertificate
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-TenantId

适用:SharePoint Online

指定要连接到的租户的 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationCertificate
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Url

适用:SharePoint Online

指定 SharePoint 管理中心的 URL。

参数属性

类型:Microsoft.Online.SharePoint.PowerShell.UrlCmdletPipeBind
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-UseSystemBrowser

适用:SharePoint Online

使用 MSAL) (Microsoft 身份验证库,通过系统浏览器对用户进行身份验证。

注意

若要避免每次运行 Connect-SPOService时添加-UseSystemBrowser该参数,可以改为设置注册表项。

将注册表项 (类型REG_DWORD设置为 UseSystemBrowser) :HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SPO\CMDLETS\

如果任一注册表项设置为非零整数值或 -UseSystemBrowser 参数设置为 true,则身份验证流将使用系统浏览器进行登录。

参数属性

类型:System.Boolean
默认值:None
支持通配符:False
不显示:False

参数集

AuthenticationUrl
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False
AuthenticationLocation
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持以下常用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

Microsoft.Online.SharePoint.PowerShell.UrlCmdletPipeBind

Microsoft.Online.SharePoint.PowerShell.CredentialCmdletPipeBind

输出

System.Object