网站搜索

如何安装/更新/卸载SharePoint Online PowerShell模块?


要求:安装 SharePoint Online PowerShell 模块。

SharePoint Online PowerShell 模块使管理员能够使用 PowerShell cmdlet 管理其 SharePoint Online 环境。 SharePoint Online 的 PowerShell 模块是管理和自动化 SharePoint 环境的好方法。您可以使用它来执行通常在 SharePoint 管理中心执行的各种任务,包括创建和管理网站、列表和库、用户和组、字段、内容等。本文将向您展示如何安装 SharePoint Online PowerShell 模块。

SharePoint Online Management Shell 现已作为 PowerShell 库中的模块提供!因此,您可以直接从 PowerShell 将其安装为模块,而无需下载和安装 SharePoint Online Management Shell MSI 文件!这使得更新更加容易。以下是安装 SharePoint Online PowerShell 模块的方法:

先决条件:Install-module cmdlet 附带“PowerShellGet”模块,该模块随 Windows 10、Windows 2016 或更高版本一起提供。在较旧的操作系统中,您可以通过 Windows Management Framework (WMF) 5.1 或更高版本获取它。

如何查找您的 SharePoint Online PowerShell 版本?

首先,请在 PowerShell 的管理模式下运行以下命令,检查您的系统中是否已安装 SharePoint Online Management Shell:


Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version

这会找到您安装的 SharePoint Online PowerShell 模块的版本。

如何安装SharePoint Online PowerShell模块?

如何从 PowerShell 安装 SharePoint Online Management Shell? SharePoint Online Management Shell 是安装在 Windows 客户端计算机或服务器中的 Windows PowerShell 模块。要安装 SharePoint Online 的 PowerShell 模块,请以管理员身份打开 PowerShell 并输入:


Install-Module Microsoft.Online.SharePoint.PowerShell

这将从 PowerShell 库安装最新的 SharePoint Online PowerShell 模块,并使管理员能够使用 PowerShell cmdlet 管理 SharePoint Online 环境。

要重新安装 SharePoint Online PowerShell 模块,请使用: -Force 开关:


Install-Module Microsoft.Online.SharePoint.PowerShell -force

请注意,安装 SharePoint Online 的 PowerShell 模块不会在您的 PC 上安装“SharePoint Online Management Shell”。不过,您仍然可以直接在 Windows PowerShell 本身中运行任何 SharePoint Online cmdlet!

让我们检查是否安装了 SharePoint Online PowerShell 模块。如果没有,请安装它。


#Check if SharePoint Online PowerShell module has been installed
Try {
    Write-host "Checking if SharePoint Online PowerShell Module is Installed..." -f Yellow -NoNewline
    $SharePointOnlineModule = Get-Module -ListAvailable "Microsoft.Online.SharePoint.PowerShell"

    #Check if SharePoint Online Module is installed
    If(!$SharePointOnlineModule)
    {
        Write-host "No!" -f Green

        #Check if script is executed under elevated user permissions - Run as Administrator
        If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
        {   
            Write-Host "Please Run this script in elevated mode (Run as Administrator)! " -NoNewline
            Read-Host "Press any key to continue"
            Exit
        }

        Write-host "Installing SharePoint Online PowerShell Module..." -f Yellow -NoNewline
        Install-Module "Microsoft.Online.SharePoint.PowerShell" -Force -Confirm:$False
        Write-host "Done!" -f Green
    }
    Else
    {
        Write-host "Yes!" -f Green
        #sharepoint online powershell module import
        Write-host "Importing SharePoint Online PowerShell Module..." -f Yellow  -NoNewline
        Import-Module "Microsoft.Online.SharePoint.PowerShell" -DisableNameChecking
        Write-host "Done!" -f Green
    }
}
Catch{
    write-host "Error: $($_.Exception.Message)" -foregroundcolor red
}

如何将 SharePoint Online 连接到 PowerShell?

安装后,您可以从 PowerShell 连接到 SharePoint Online 租户并开始使用 SharePoint Online PowerShell cmdlet。

  • 步骤 1:导入 SharePoint Online PowerShell 模块
  • 步骤 2:从 PowerShell 连接到 SharePoint Online
  • 步骤 3:运行 SharePoint Online 的 PowerShell cmdlet

#Import PowerShell module for SharePoint Online 
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Connect to SharePoint Online
Connect-SPOService -url "https://crescent-admin.sharepoint.com" -Credential (Get-Credential)

#Get All SharePoint Sites
Get-SPOSite

此 PowerShell 脚本提示输入用户名和密码(您可以保留凭据参数以从多重身份验证 - 启用 MFA 的帐户进行连接),连接到 SharePoint Online,并使用 Get-SPOSite cmdlet 获取所有 SharePoint Online 网站。确保根据您的环境更改站点 URL。有关从 PowerShell 连接到 SharePoint Online 的更多信息:如何从 PowerShell 连接到 SharePoint Online?

更新 SharePoint Online PowerShell 模块

如何更新 SharePoint Online 管理 shell?要更新 SharePoint Online PowerShell 模块,请使用以下命令:


Update-module microsoft.online.sharepoint.powershell

键入“A”以确认全部为“是”,然后按 Enter 键更新 SharePoint Online 的 PowerShell 模块。

卸载 SharePoint Online PowerShell 模块

要删除 SharePoint Online PowerShell 模块,请使用以下 cmdlet:


Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell

如果您安装了多个版本,请使用“-AllVersions”开关。确保您在 PowerShell 控制台中以管理员身份运行这些 cmdlet。

SharePoint Online PowerShell 命令

安装 SharePoint Online PowerShell 模块后,您可以使用以下命令从该模块获取 cmdlet 列表:


Get-command -Module Microsoft.Online.SharePoint.PowerShell

Cmdlet Name
Add-SPOGeoAdministrator
Add-SPOHubSiteAssociation
Add-SPOHubToHubAssociation
Add-SPOOrgAssetsLibrary
Add-SPOSiteCollectionAppCatalog
Add-SPOSiteDesign
Add-SPOSiteDesignTask
Add-SPOSiteScript
Add-SPOSiteScriptPackage
Add-SPOTenantCdnOrigin
Add-SPOTheme
Add-SPOUser
Approve-SPOTenantServicePrincipalPermissionGrant
Approve-SPOTenantServicePrincipalPermissionRequest
Connect-SPOService
ConvertTo-SPOMigrationEncryptedPackage
ConvertTo-SPOMigrationTargetedPackage
Deny-SPOTenantServicePrincipalPermissionRequest
Disable-SPOTenantServicePrincipal
Disconnect-SPOService
Enable-SPOCommSite
Enable-SPOTenantServicePrincipal
Export-SPOQueryLogs
Export-SPOUserInfo
Export-SPOUserProfile
Get-IsCommSite
Get-SPOAppErrors
Get-SPOAppInfo
Get-SPOBrowserIdleSignOut
Get-SPOBuiltInDesignPackageVisibility
Get-SPOCrossGeoMovedUsers
Get-SPOCrossGeoMoveReport
Get-SPOCrossGeoUsers
Get-SPODataEncryptionPolicy
Get-SPODeletedSite
Get-SPOExternalUser
Get-SPOGeoAdministrator
Get-SPOGeoMoveCrossCompatibilityStatus
Get-SPOGeoStorageQuota
Get-SPOHideDefaultThemes
Get-SPOHomeSite
Get-SPOHubSite
Get-SPOKnowledgeHubSite
Get-SPOMigrationJobProgress
Get-SPOMigrationJobStatus
Get-SPOMultiGeoCompanyAllowedDataLocation
Get-SPOMultiGeoExperience
Get-SPOOrgAssetsLibrary
Get-SPOOrgNewsSite
Get-SPOPublicCdnOrigins
Get-SPOSite
Get-SPOSiteCollectionAppCatalogs
Get-SPOSiteContentMoveState
Get-SPOSiteDataEncryptionPolicy
Get-SPOSiteDesign
Get-SPOSiteDesignRights
Get-SPOSiteDesignRun
Get-SPOSiteDesignRunStatus
Get-SPOSiteDesignTask
Get-SPOSiteGroup
Get-SPOSiteRenameState
Get-SPOSiteScript
Get-SPOSiteScriptFromList
Get-SPOSiteScriptFromWeb
Get-SPOSiteUserInvitations
Get-SPOStorageEntity
Get-SPOStructuralNavigationCacheSiteState
Get-SPOStructuralNavigationCacheWebState
Get-SPOTenant
Get-SPOTenantCdnEnabled
Get-SPOTenantCdnOrigins
Get-SPOTenantCdnPolicies
Get-SPOTenantContentTypeReplicationParameters
Get-SPOTenantLogEntry
Get-SPOTenantLogLastAvailableTimeInUtc
Get-SPOTenantOrgRelation
Get-SPOTenantOrgRelationByPartner
Get-SPOTenantOrgRelationByScenario
Get-SPOTenantServicePrincipalPermissionGrants
Get-SPOTenantServicePrincipalPermissionRequests
Get-SPOTenantSyncClientRestriction
Get-SPOTenantTaxonomyReplicationParameters
Get-SPOTheme
Get-SPOUnifiedGroup
Get-SPOUnifiedGroupMoveState
Get-SPOUser
Get-SPOUserAndContentMoveState
Get-SPOUserOneDriveLocation
Get-SPOWebTemplate
Grant-SPOHubSiteRights
Grant-SPOSiteDesignRights
Invoke-SPOMigrationEncryptUploadSubmit
Invoke-SPOSiteDesign
Invoke-SPOSiteSwap
New-SPOMigrationEncryptionParameters
New-SPOMigrationPackage
New-SPOPublicCdnOrigin
New-SPOSdnProvider
New-SPOSite
New-SPOSiteGroup
New-SPOSiteSharingReportJob
New-SPOTenantOrgRelation
Register-SPODataEncryptionPolicy
Register-SPOHubSite
Remove-SPODeletedSite
Remove-SPOExternalUser
Remove-SPOGeoAdministrator
Remove-SPOHomeSite
Remove-SPOHubSiteAssociation
Remove-SPOHubToHubAssociation
Remove-SPOKnowledgeHubSite
Remove-SPOMigrationJob
Remove-SPOMultiGeoCompanyAllowedDataLocation
Remove-SPOOrgAssetsLibrary
Remove-SPOOrgNewsSite
Remove-SPOPublicCdnOrigin
Remove-SPOSdnProvider
Remove-SPOSite
Remove-SPOSiteCollectionAppCatalog
Remove-SPOSiteCollectionAppCatalogById
Remove-SPOSiteDesign
Remove-SPOSiteDesignTask
Remove-SPOSiteGroup
Remove-SPOSiteScript
Remove-SPOSiteSharingReportJob
Remove-SPOSiteUserInvitations
Remove-SPOStorageEntity
Remove-SPOTenantCdnOrigin
Remove-SPOTenantOrgRelation
Remove-SPOTenantSyncClientRestriction
Remove-SPOTheme
Remove-SPOUser
Remove-SPOUserInfo
Remove-SPOUserProfile
Repair-SPOSite
Request-SPOPersonalSite
Request-SPOUpgradeEvaluationSite
Restore-SPODataEncryptionPolicy
Restore-SPODeletedSite
Revoke-SPOHubSiteRights
Revoke-SPOSiteDesignRights
Revoke-SPOTenantServicePrincipalPermission
Revoke-SPOUserSession
Set-SPOBrowserIdleSignOut
Set-SPOBuiltInDesignPackageVisibility
Set-SPOGeoStorageQuota
Set-SPOHideDefaultThemes
Set-SPOHomeSite
Set-SPOHubSite
Set-SPOKnowledgeHubSite
Set-SPOMigrationPackageAzureSource
Set-SPOMultiGeoCompanyAllowedDataLocation
Set-SPOMultiGeoExperience
Set-SPOOrgAssetsLibrary
Set-SPOOrgNewsSite
Set-SPOSite
Set-SPOSiteDesign
Set-SPOSiteGroup
Set-SPOSiteOffice365Group
Set-SPOSiteScript
Set-SPOSiteScriptPackage
Set-SPOStorageEntity
Set-SPOStructuralNavigationCacheSiteState
Set-SPOStructuralNavigationCacheWebState
Set-SPOTenant
Set-SPOTenantCdnEnabled
Set-SPOTenantCdnPolicy
Set-SPOTenantContentTypeReplicationParameters
Set-SPOTenantSyncClientRestriction
Set-SPOTenantTaxonomyReplicationParameters
Set-SPOUnifiedGroup
Set-SPOUser
Set-SPOWebTheme
Start-SPOSiteContentMove
Start-SPOSiteRename
Start-SPOUnifiedGroupMove
Start-SPOUserAndContentMove
Stop-SPOSiteContentMove
Stop-SPOUserAndContentMove
Submit-SPOMigrationJob
Test-SPOSite
Unregister-SPOHubSite
Update-SPODataEncryptionPolicy
Update-UserType
Upgrade-SPOSite
Verify-SPOTenantOrgRelation

客户端对象模型是 SharePoint Online PowerShell 模块的子集(如果导入 SharePoint PowerShell 模块,则不必添加对 CSOM 程序集的引用)。 SharePoint PnP PowerShell cmdlet 也为此领域增添了巨大的价值。要安装 SharePoint Online PnP PowerShell 模块,请参阅:安装 SharePoint Online PnP PowerShell 模块

包起来

安装 SharePoint Online PowerShell 模块是一个简单的过程,可以极大地提高管理员的工作效率并简化 SharePoint Online 资源的管理。通过执行本文中概述的步骤,管理员可以轻松安装该模块并开始使用其强大的功能来自动执行任务和管理 SharePoint Online。无论您使用的是小型还是大型 SharePoint Online 环境,SharePoint Online PowerShell 模块都提供了一种灵活且高效的方法来管理 SharePoint Online 租户。

经常问的问题:

如何导入 SharePoint Online PowerShell 模块?

安装 SharePoint Online PowerShell 模块后,使用“Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking”将该模块导入到 PowerShell 脚本中。

如何使用 SharePoint Online PnP PowerShell?

安装 SharePoint Online 的 PnP PowerShell 模块后,您可以连接 SharePoint Online 网站(而不是 SharePoint 管理中心)并使用该模块中任何可用的 PowerShell cmdlet。
更多信息:安装 SharePoint Online PnP PowerShell模块

我拥有什么版本的 SharePoint Online Management Shell?

要查找 SharePoint Online PowerShell 模块版本,请使用:“Get-Module Microsoft.Online.SharePoint.PowerShell -ListAvailable |选择名称、版本”

我们可以使用 PowerShell 连接到 SharePoint Online 网站吗?

当然,是的!我们可以使用 PowerShell 连接到 SharePoint Online 网站。首先,我们需要安装 SharePoint Online Management Shell 并连接到 SharePoint Online。例如,Connect-SPOService -Url https://YourDomain-admin.sharepoint.com,指定 SharePoint Online 管理站点的 URL 以及具有管理权限的用户的凭据。连接后,我们可以使用 PowerShell cmdlet 来管理 SharePoint Online 网站!

相关文章